# HG changeset patch # User Adam Chlipala # Date 1221149542 14400 # Node ID cd4cabaf3e52bd9d40c63505dc3abe07714c395f # Parent 132416711463a2e97395cfc1e88a62ebc6dbc777 Fix memory management bug diff -r 132416711463 -r cd4cabaf3e52 src/c/urweb.c --- a/src/c/urweb.c Thu Sep 11 11:53:33 2008 -0400 +++ b/src/c/urweb.c Thu Sep 11 12:12:22 2008 -0400 @@ -145,7 +145,7 @@ static void uw_check_heap(uw_context ctx, size_t extra) { if (ctx->heap_back - ctx->heap_front < extra) { - size_t desired = ctx->heap_back - ctx->heap + extra, next; + size_t desired = ctx->heap_front - ctx->heap + extra, next; char *new_heap; next = ctx->heap_back - ctx->heap; @@ -154,7 +154,7 @@ for (; next < desired; next *= 2); new_heap = realloc(ctx->heap, next); - ctx->heap_front = new_heap + (ctx->heap_back - ctx->heap_front); + ctx->heap_front = new_heap + (ctx->heap_front - ctx->heap); ctx->heap_back = new_heap + next; if (new_heap != ctx->heap) { @@ -195,7 +195,7 @@ } static void uw_check(uw_context ctx, size_t extra) { - size_t desired = ctx->page_back - ctx->page + extra, next; + size_t desired = ctx->page_front - ctx->page + extra, next; char *new_page; next = ctx->page_back - ctx->page; @@ -578,7 +578,7 @@ } void uw_Basis_htmlifyString_w(uw_context ctx, uw_Basis_string s) { - uw_check(ctx, strlen(s) * 5); + uw_check(ctx, strlen(s) * 6); for (; *s; s++) { char c = *s;