On Tue, Aug 02, 2011 at 04:58:19PM +0200, Denys Vlasenko wrote:
I don't see it. Let me walk it through:
char *msg = xasprintf("%s", result);
^^^^^^^^^^^^^ we allocated new string, msg
res = new_report_result(REPORT_RESULT_TYPE_MESSAGE, msg);
^^^^^^^^^^^^^ we use it to build res
new_report_result accepts char *, msg is now owned by the struct
msg = format_report_result(res);
^^^^^^^^^^^^^ we create final message string from res
and assign it to msg. Here we lost old msg pointer
during assignment. It's leaked.
The original msg is now freed.
If you think new_report_result should accept const char * instead, we
can add the extra strdup+free calls.