[Geany-devel] [Patch] memory leaks in tagmanager/tm_workspace.c

Daniel Marjamaki danielm77 at xxxxx
Sun Jun 6 09:49:46 UTC 2010


Hello!

This code has memory leaks, either if theWorkspace is NULL or if the
fopen fails.

#ifdef G_OS_WIN32
    char *temp_file = g_strdup_printf("%s\\_%d_%ld_1.cpp", config_dir,
getpid(), time(NULL));
    char *temp_file2 = g_strdup_printf("%s\\_%d_%ld_2.cpp", config_dir,
getpid(), time(NULL));
#else
    char *temp_file = g_strdup_printf("%s/%d_%ld_1.cpp", config_dir,
getpid(), time(NULL));
    char *temp_file2 = g_strdup_printf("%s/%d_%ld_2.cpp", config_dir,
getpid(), time(NULL));
#endif

    if (NULL == theWorkspace || NULL == (fp = g_fopen(temp_file, "w")))
        return FALSE;

I changed it to:

#ifdef G_OS_WIN32
    char *temp_file = g_strdup_printf("%s\\_%d_%ld_1.cpp", config_dir,
getpid(), time(NULL));
    char *temp_file2 = g_strdup_printf("%s\\_%d_%ld_2.cpp", config_dir,
getpid(), time(NULL));
#else
    char *temp_file = g_strdup_printf("%s/%d_%ld_1.cpp", config_dir,
getpid(), time(NULL));
    char *temp_file2 = g_strdup_printf("%s/%d_%ld_2.cpp", config_dir,
getpid(), time(NULL));
#endif

    if (NULL == theWorkspace || NULL == (fp = g_fopen(temp_file, "w")))
    {
        g_free(temp_file);
        g_free(temp_file2);
        return FALSE;
    }

Best regards,
Daniel





<P><p><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR>Parfym och kosmetik upp till 50% billigare hos BeautyPlanet.se - <a style="font-family: Tahoma, sans-serif; font-size: 12px; color: #00f" href="http://secure-dk.imrworldwide.com/cgi-bin/b?ci=aller-kampanj-se&cg=spray&tu=http%3A%2F%2Fwww.beautyplanet.se%2F%3Futm_source%3DSpray%26utm_medium%3DMailfooter%26utm_campaign%3DGenerell" target="_blank"> Klicka här!</a></font>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.geany.org/pipermail/devel/attachments/20100606/7c4c4d56/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: memleak.patch
Type: application/octet-stream
Size: 462 bytes
Desc: not available
URL: <http://lists.geany.org/pipermail/devel/attachments/20100606/7c4c4d56/attachment.obj>


More information about the Devel mailing list