Better: Move the first asprintf in the else branch. There is no point to run that statement in case of an error message:The fix for that is adding a free() after the if
C:
if(memcmp("*ERROR*", ret, 7) == 0)
asprintf(&message, "[%d] %s : %s - \"%s\"", tests_run, ret, label, errmsg);
else
asprintf(&message, "[%d] %s : %s", tests_run, ret, label);
Then the existing
free(message); will free either of them.Even better:
C:
if(memcmp("*ERROR*", ret, 7) != 0)
asprintf(&message, "[%d] %s : %s", tests_run, ret, label);
else
asprintf(&message, "[%d] %s : %s - \"%s\"", tests_run, ret, label, errmsg);
Since non-error messages are (hopefully) more common, it makes sense to switch the branches.