Fix memory leak in tzparser.c
Shixin Wang <wang-shi-xin@outlook.com>
From: Shixin Wang <wang-shi-xin@outlook.com>
To: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2025-12-16T05:55:32Z
Lists: pgsql-hackers
Attachments
- v1-0001-Fix-memory-leak-in-tzparser.patch (application/octet-stream) patch v1-0001
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