Parameter parser leaks memory

Issue #1519 closed
Roland Haas created an issue

The function cctk_PirahaParser in src/piraha/Call.cc wraps each argument to its set_function (points to CCTKi_SetParameter) in a strdup (with the exception of ActiveThorns). This leads to a memory leak since CTKi_SetParameter does not free() them. To test, run a minimal parfile

Cactus::cctk_itlast = 42

with an executable from an empty thornlist through valgrind:

valgrind  --log-file=valgrind.log --leak-check=full --tool=memcheck cactus_null answer.par

and you will find eg

==27121== 20 bytes in 1 blocks are definitely lost in loss record 297 of 1,362
==27121==    at 0x4C2935B: malloc (vg_replace_malloc.c:270)
==27121==    by 0x6249D91: strdup (strdup.c:42)
==27121==    by 0x43D1C1: cctk_PirahaParser (Call.cc:875)
==27121==    by 0x419855: CCTKi_ProcessParameterDatabase (ProcessParameterDatabase.c:158)
==27121==    by 0x416760: CCTKi_InitialiseCactus (InitialiseCactus.c:101)
==27121==    by 0x415FFD: main (flesh.cc:64)

The attached patch fixes this. There is still some memory leakage (couple hundred bytes that seem to be due to the flesh and persist even when the old parser is reactivated).

Keyword:

Comments (5)

  1. Steven R. Brandt
    • changed status to open
    • removed comment

    I agree. I can't remember why I thought the strdup()'s were necessary, but the seem to not be needed. Please apply.

  2. Log in to comment