Fix memory leak in tzparser.c - Mailing list pgsql-hackers

From Shixin Wang
Subject Fix memory leak in tzparser.c
Date
Msg-id 13537FFC-5C55-470E-A75B-18F32186F301@outlook.com
Whole thread Raw
Responses Re: Fix memory leak in tzparser.c
List pgsql-hackers
Hi hackers,

I noticed a memory leak in the addToArray() function in src/backend/utils/misc/tzparser.c.
When the override parameter is true and a duplicate timezone abbreviation is found,
the code overwrites midptr->zone without freeing the previously allocated memory.

The fix would be:

-               midptr->zone = entry->zone;
+               if (midptr->zone != NULL)
+                   pfree(midptr->zone);
+               midptr->zone = entry->zone;

While the memory is managed by a temp memory context that gets cleaned up
eventually, the coarse-grained management might cause some memory to
accumulate during ParseTzFile() recursive calls when processing @INCLUDE
directives.

I've attached a patch with this change in case anyone thinks it's worth
applying.

Regards,
Shixin Wang




Attachment

pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: Re: Implement waiting for wal lsn replay: reloaded
Next
From: Michael Paquier
Date:
Subject: Re: Fix crash during recovery when redo segment is missing