- From: Diana X Bruk <bruk_diana@jpmorgan.com>
- Date: Wed, 29 Dec 1999 10:22:26 -0500
- To: www-lib@w3.org
The patch changes generate a warning message at pEl->token.
To get rid of the warning I recommend the following slight change to the code.
Here is the diff I produced after I applied the patch and then removed the
warning:
Index: HTMIMPrs.c
===================================================================
RCS file: /home/cvs/.cvsroot-alib/oss/libwww/Library/src/HTMIMPrs.c,v
retrieving revision 1.3
diff -c -r1.3 HTMIMPrs.c
*** 79,90 ****
{
int i;
HTMIMEParseEl * pEl, * next;
if(me && me->parsers) {
for (i=0; i<me->size; i++) {
for (pEl = me->parsers[i]; pEl; pEl = next) {
next = pEl->next;
! HT_FREE(pEl->token);
HT_FREE(pEl);
}
}
--- 79,92 ----
{
int i;
HTMIMEParseEl * pEl, * next;
+ void * temp;
if(me && me->parsers) {
for (i=0; i<me->size; i++) {
for (pEl = me->parsers[i]; pEl; pEl = next) {
next = pEl->next;
! temp = (void *)(pEl->token);
! HT_FREE(temp);
HT_FREE(pEl);
}
}
andyl@infospinner.com on 12/28/99 11:28:37 AM
To: www-lib@w3.org
cc: (bcc: Diana X Bruk)
Subject: Patches for various leaks
Attached find CVS diff files to 2 source files that clean up a few memory
leaks when an app shuts down.
The first, HTIcons.c, adds the function HTIcon_deleteAll(), a function to
undo the effects of HTIconInit(). It clears out the entire icon table,
deleting all elements and nukes the table.
The second, HTMIMPrs.c, fixes the function HTParseSet_deleteAll() which had
the following problems:
1) free'd each element twice
2) the element tokens (pEl->token) was never being free'd
3) the parser hash table itself (me->parsers) was never freed.
Andy Levine
andyl@infospinner.com
Index: HTIcons.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTIcons.c,v
retrieving revision 2.29
diff -r2.29 HTIcons.c
243a244,283
>
> PRIVATE void HTIconNode_delete(HTIconNode* pNode)
> {
> HT_FREE(pNode->icon_url);
> HT_FREE(pNode->icon_alt);
> HT_FREE(pNode->type_templ);
> HT_FREE(pNode);
> }
>
> /*
> ** cleans up all memory used by icons. Should be called by
> ** HTLibTerminate() (but it isn't)
> **
> */
> PUBLIC void HTIcon_deleteAll()
> {
> if(icons != NULL)
> {
> HTList * iconList = icons;
> HTIconNode * node;
>
> while((node = (HTIconNode*)HTList_removeLastObject(iconList)))
> {
> HTIconNode_delete(node);
> }
>
> /* delete the list as well */
> HTList_delete(icons);
> icons = NULL;
> }
>
> HTIconNode_delete(icon_unknown);
> icon_unknown = NULL;
> HTIconNode_delete(icon_blank);
> icon_blank = NULL;
> HTIconNode_delete(icon_parent);
> icon_parent = NULL;
> HTIconNode_delete(icon_dir);
> icon_dir = NULL;
> }
Index: HTMIMPrs.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTMIMPrs.c,v
retrieving revision 2.9
diff -r2.9 HTMIMPrs.c
82,87d81
<
< for (i=0; i<me->size; i++)
< for (pEl = me->parsers[i]; pEl; pEl = next) {
< next = pEl->next;
< HT_FREE(pEl);
< }
89,91c83,92
< for (pEl = me->parsers[i]; pEl; pEl = next) {
< next = pEl->next;
< HT_FREE(pEl);
---
> if(me && me->parsers) {
> for (i=0; i<me->size; i++) {
> for (pEl = me->parsers[i]; pEl; pEl = next) {
> next = pEl->next;
> HT_FREE(pEl->token);
> HT_FREE(pEl);
> }
> }
> HT_FREE(me->parsers);
> HT_FREE(me);
93d93
< HT_FREE(me);
Received on Wednesday, 29 December 1999 10:22:50 UTC