tstorch / mongoose

Automatically exported from code.google.com/p/mongoose
MIT License
0 stars 0 forks source link

Error allocating mg_context on mg_start #312

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It seems that there is an error on allocating mg_context inside mg_start:

actual -> ctx = (struct mg_context *) calloc(1, sizeof(*ctx));

corrected -> ctx = (struct mg_context *) calloc(1, sizeof(ctx));

Instead of allocating memory for the structure it's allocating only memory for 
a pointer to a structure.

Original issue reported on code.google.com by mingo...@gmail.com on 2 Feb 2012 at 9:11

GoogleCodeExporter commented 9 years ago
Please output sizeof(*ctx) and sizeof(ctx) and compare.

Original comment by valenok on 2 Feb 2012 at 9:15

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I did and the result is:
printf("%d : %d\n", sizeof(ctx), sizeof(*ctx)); -> 4 : 1288

Original comment by mingo...@gmail.com on 2 Feb 2012 at 9:55

GoogleCodeExporter commented 9 years ago
if we only allocate memory for a pinter we should not use it as it is done now:

  ctx = (struct mg_context *) calloc(1, sizeof(*ctx));
  ctx->user_callback = user_callback; <<<< writing to unallocated memory
  ctx->user_data = user_data; <<<< writing to unallocated memory

This is done with mingw 4.6.2

Original comment by mingo...@gmail.com on 2 Feb 2012 at 9:58