comparison src/c/urweb.c @ 2296:5104e480b3e3

Fix a few C memory bugs
author Adam Chlipala <adam@chlipala.net>
date Thu, 19 Nov 2015 10:31:47 -0500
parents 50ad02829abd
children 6d56080f495c
comparison
equal deleted inserted replaced
2295:e6c5bb62fef8 2296:5104e480b3e3
599 ctx->recordingOffset = 0; 599 ctx->recordingOffset = 0;
600 ctx->cacheUpdate = NULL; 600 ctx->cacheUpdate = NULL;
601 ctx->cacheUpdateTail = NULL; 601 ctx->cacheUpdateTail = NULL;
602 602
603 ctx->remoteSock = -1; 603 ctx->remoteSock = -1;
604
605 ctx->cacheUnlock = NULL;
604 606
605 return ctx; 607 return ctx;
606 } 608 }
607 609
608 size_t uw_inputs_max = SIZE_MAX; 610 size_t uw_inputs_max = SIZE_MAX;
3679 int r = setjmp(ctx->jmp_buf); 3681 int r = setjmp(ctx->jmp_buf);
3680 3682
3681 if (r == 0) { 3683 if (r == 0) {
3682 uw_ensure_transaction(ctx); 3684 uw_ensure_transaction(ctx);
3683 ctx->app->initializer(ctx); 3685 ctx->app->initializer(ctx);
3684 if (ctx->app->db_commit(ctx)) 3686 if (uw_commit(ctx))
3685 uw_error(ctx, FATAL, "Error running SQL COMMIT"); 3687 uw_error(ctx, FATAL, "Error running SQL COMMIT");
3686 } 3688 }
3687 3689
3688 return r; 3690 return r;
3689 } 3691 }
4624 static char *uw_Sqlcache_allocKeyBuffer(char **keys, size_t numKeys) { 4626 static char *uw_Sqlcache_allocKeyBuffer(char **keys, size_t numKeys) {
4625 size_t len = 0; 4627 size_t len = 0;
4626 while (numKeys-- > 0) { 4628 while (numKeys-- > 0) {
4627 char* k = keys[numKeys]; 4629 char* k = keys[numKeys];
4628 if (!k) { 4630 if (!k) {
4629 // Can only happen when flushihg, in which case we don't need anything past the null key. 4631 // Can only happen when flushing, in which case we don't need anything past the null key.
4630 break; 4632 break;
4631 } 4633 }
4632 // Leave room for separator. 4634 // Leave room for separator.
4633 len += 1 + strlen(k); 4635 len += 1 + strlen(k);
4634 } 4636 }
4693 time_t timeNow = uw_Sqlcache_getTimeNow(cache); 4695 time_t timeNow = uw_Sqlcache_getTimeNow(cache);
4694 uw_Sqlcache_Entry *entry; 4696 uw_Sqlcache_Entry *entry;
4695 if (numKeys == 0) { 4697 if (numKeys == 0) {
4696 entry = cache->table; 4698 entry = cache->table;
4697 if (!entry) { 4699 if (!entry) {
4698 entry = malloc(sizeof(uw_Sqlcache_Entry)); 4700 entry = calloc(1, sizeof(uw_Sqlcache_Entry));
4699 entry->key = NULL; 4701 entry->key = NULL;
4700 entry->value = NULL; 4702 entry->value = NULL;
4701 entry->timeInvalid = 0; 4703 entry->timeInvalid = 0;
4702 cache->table = entry; 4704 cache->table = entry;
4703 } 4705 }
4707 while (numKeys-- > 0) { 4709 while (numKeys-- > 0) {
4708 buf = uw_Sqlcache_keyCopy(buf, keys[numKeys]); 4710 buf = uw_Sqlcache_keyCopy(buf, keys[numKeys]);
4709 size_t len = buf - key; 4711 size_t len = buf - key;
4710 entry = uw_Sqlcache_find(cache, key, len, 1); 4712 entry = uw_Sqlcache_find(cache, key, len, 1);
4711 if (!entry) { 4713 if (!entry) {
4712 entry = malloc(sizeof(uw_Sqlcache_Entry)); 4714 entry = calloc(1, sizeof(uw_Sqlcache_Entry));
4713 entry->key = strdup(key); 4715 entry->key = strdup(key);
4714 entry->value = NULL; 4716 entry->value = NULL;
4715 entry->timeInvalid = 0; 4717 entry->timeInvalid = 0;
4716 uw_Sqlcache_add(cache, entry, len); 4718 uw_Sqlcache_add(cache, entry, len);
4717 } 4719 }