Skip to content

Commit

Permalink
GH-5 Clear initial context memory for Valgrind (just in case).
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWumpus committed Jul 28, 2024
1 parent 2a805bc commit 429bfdf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/post4.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,10 +1168,13 @@ p4Create(P4_Options *opts)
ctx->argv = opts->argv;
ctx->state = P4_STATE_INTERPRET;

if ((ctx->mem = malloc(opts->mem_size * 1024)) == NULL) {
/* GH-5 Clear initial memory space to placate Valgrind. */
if ((ctx->mem = calloc(1, opts->mem_size * 1024)) == NULL) {
goto error0;
}
/* GH-5 Subdue valgrind uninitialised values with BYTE_ME. */
/* GH-5 Setting memory to something other than zero can
* help debug possible memory use before initialising.
*/
MEMSET(ctx->mem, BYTE_ME, opts->mem_size * 1024);
ctx->end = ctx->mem + opts->mem_size * 1024;
ctx->here = ctx->mem;
Expand Down

0 comments on commit 429bfdf

Please sign in to comment.