On Tue, 2011-08-02 at 15:38 +0200, Miroslav Lichvar wrote:
On Tue, Aug 02, 2011 at 03:36:20PM +0200, Denys Vlasenko wrote:
On Fri, 2011-07-22 at 13:37 +0200, Miroslav Lichvar wrote:
char *msg = xasprintf("%s", result);
res = new_report_result(REPORT_RESULT_TYPE_MESSAGE, msg);
msg = format_report_result(res); <--- HERE
Memory leak: xasprintf result is lost.
It's freed in the free_report_result call.
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 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.