IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Opened 21 years ago

Closed 21 years ago

Last modified 20 years ago

#505 closed defect (invalid)

Memory leak in psMetadataAddItem

Reported by: Paul Price Owned by: robert.desonia@…
Priority: high Milestone:
Component: types Version: 0.6.0
Severity: normal Keywords:
Cc:

Description

The following program leaks memory from psMetadataAddItem (presumably due to
replacing the MD item):

#include <stdio.h>
#include "pslib.h"

int main(void)
{

psMetadata *md = psMetadataAlloc();
psMetadataAdd(md, PS_LIST_TAIL, "answer", PS_META_STR, "The big answer",

"Forty-two");

psMetadataItem *answerItem = psMetadataItemAlloc("answer", PS_META_STR, "New

answer", "Three");

psMetadataAddItem(md, answerItem, PS_LIST_TAIL, PS_META_REPLACE);
int answer = psMetadataLookupS32(NULL, md, "answer");
printf("Answer: %d\n", answer);

Check
psMemCheckCorruption(true);
psFree(md);
psMemBlock leaks = NULL;
List of leaks
int nLeaks = psMemCheckLeaks(0, &leaks, NULL, false); Number of leaks
printf("%d leaks found.\n", nLeaks);
for (int i = 0; i < nLeaks; i++) {

printf("Memory leak detection: memBlock %lld\n"

"\tFile %s, line %d, size %d\n",
leaks[i]->id, leaks[i]->file, leaks[i]->lineno, leaks[i]->userMemorySize);

}


Pau.

}

price@mithrandir:/home/mithrandir/price/IP3/scripts/src/phase2>./test
2005:08:13 00:21:30Z|mithrandir |W|psMetadataAddItem

Metadata item answer has been replaced

Answer: 0
4 leaks found.
Memory leak detection: memBlock 18

File psString.c, line 51, size 2048

Memory leak detection: memBlock 17

File psMetadata.c, line 205, size 1024

Memory leak detection: memBlock 16

File psString.c, line 33, size 16

Memory leak detection: memBlock 15

File psMetadata.c, line 184, size 32

Also, the warning about replacement shouldn't be displayed --- it was the
programmer's intention to replace (PS_META_REPLACE).

Change History (4)

comment:1 by David.Robbins@…, 21 years ago

Resolution: invalid
Status: newclosed

Paul,

you allocate the psMetadataItem 'answerItem' and never free it. I added a call
to psFree in your code and it works fine. 0 memory leaks.
I did remove the printing that the item has been replaced.

-Dave

comment:2 by Paul Price, 21 years ago

Thanks!

comment:3 by Paul Price, 20 years ago

Keywords: VERIFIED added

Bug has been resolved.... closing.

comment:4 by Paul Price, 20 years ago

Keywords: VERIFIED removed

Bugs have been fixed... closing.

Note: See TracTickets for help on using tickets.