RE: Memory leak patch

Well, this is the second time for this patch.  Is there any way that we can
get past patches applied?

-----Original Message-----
From: Mike Kumbera [mailto:kumbera@battra.llnl.gov]
Sent: Wednesday, May 31, 2000 2:29 PM
To: www-lib@w3.org
Subject: Memory leak patch




I would like to submit a patch for a memory leak in the package:
libwww/Library/src/HTHome.c

There is a memory leak in the HTTmpAnchor function that was showing itself
in calls to HTEventList_loop (if I recall).

It's clear that the memory allocated in 'result' can never be given to
HT_FREE(). I
changed the routine to free 'result' before it returns.

If you have any questions or problems with this let me know. I've been
running 
with this fix in my code for a few months and have had no problems. Purify
also
shows no memory leaks any more!

(nospam_kumbera1@llnl.gov)
Mike 


----------------------------Distributed VERSION
-----------------------------------
PUBLIC HTParentAnchor * HTTmpAnchor (HTUserProfile * up)
{
    static int offset = 0;                          /* Just keep counting...
*/
    time_t t = time(NULL);
    char * tmpfile = HTGetTmpFileName(HTUserProfile_tmp(up));
    char * tmpurl = HTParse(tmpfile, "file:", PARSE_ALL);
    if (tmpfile && tmpurl && t >= 0) {
        char * result;
        if (!(result = (char *) HT_MALLOC(strlen(tmpurl)+20)))
            HT_OUTOFMEM("HTTmpAnchor");
#ifdef HAVE_LONG_TIME_T
        sprintf(result, "%s.%ld.%d", tmpurl, t, offset++);
#else
        sprintf(result, "%s.%d.%d", tmpurl, t, offset++);
#endif
        HTTRACE(APP_TRACE, "Tmp Anchor.. With location `%s\'\n" _ result);
        return HTAnchor_parent(HTAnchor_findAddress(result));
        HT_FREE(result);
    }
    HT_FREE(tmpfile);
    HT_FREE(tmpurl);
    return NULL;
}



----------------------------My VERSION -----------------------------------
PUBLIC HTParentAnchor * HTTmpAnchor (HTUserProfile * up)
{
    HTParentAnchor * htpa = NULL;
    static int offset = 0;                          /* Just keep counting...
*/
    time_t t = time(NULL);
    char * tmpfile = HTGetTmpFileName(HTUserProfile_tmp(up));
    char * tmpurl = HTParse(tmpfile, "file:", PARSE_ALL);
    if (tmpfile && tmpurl && t >= 0) {
        char * result;
        if (!(result = (char *) HT_MALLOC(strlen(tmpurl)+20)))
            HT_OUTOFMEM("HTTmpAnchor");
#ifdef HAVE_LONG_TIME_T
        sprintf(result, "%s.%ld.%d", tmpurl, t, offset++);
#else
        sprintf(result, "%s.%d.%d", tmpurl, t, offset++);
#endif
        HTTRACE(APP_TRACE, "Tmp Anchor.. With location `%s\'\n" _ result);
        htpa = HTAnchor_parent(HTAnchor_findAddress(result));
        HT_FREE(result);
    }
    HT_FREE(tmpfile);
    HT_FREE(tmpurl);
    return(htpa);
}


---------------------------- Patch (cut here)---------------------------
--- w3c-libwww-5.2.8/Library/src/HTHome.c.orig  Tue Dec  7 15:18:36 1999
+++ w3c-libwww-5.2.8/Library/src/HTHome.c       Tue Dec  7 15:18:25 1999
@@ -145,6 +145,7 @@
 */
 PUBLIC HTParentAnchor * HTTmpAnchor (HTUserProfile * up)
 {
+    HTParentAnchor * htpa = NULL;
     static int offset = 0;                         /* Just keep counting...
*/
     time_t t = time(NULL);
     char * tmpfile = HTGetTmpFileName(HTUserProfile_tmp(up));
@@ -159,12 +160,12 @@
        sprintf(result, "%s.%d.%d", tmpurl, t, offset++);
 #endif
        HTTRACE(APP_TRACE, "Tmp Anchor.. With location `%s\'\n" _ result);
-       return HTAnchor_parent(HTAnchor_findAddress(result));
+       htpa = HTAnchor_parent(HTAnchor_findAddress(result));
        HT_FREE(result);
     }
     HT_FREE(tmpfile);
     HT_FREE(tmpurl);
-    return NULL;
+    return(htpa);
 }

 /*

Received on Monday, 5 June 2000 08:57:10 UTC