Mercurial > urweb
diff src/c/urweb.c @ 321:cd4cabaf3e52
Fix memory management bug
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 11 Sep 2008 12:12:22 -0400 |
parents | 6a4e365db60c |
children | 5030e909fbf3 |
line wrap: on
line diff
--- 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;