[Patch] timezone/zic.c: Fix file handle leak in dolink()

Started by zengman9 months ago5 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t52979
psql -h localhost -U postgres

Built from patchset v2 (message #2), September 20, 2026 at 09:15 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t52979_2 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t52979_2 && git checkout t52979_2

Patchset v2 (message #2) is on t52979_2

Jump to latest
#1zengman
zengman@halodbtech.com

Hi all,

I noticed a small issue and made a tiny patch to fix it — it addresses a file handle leak in the dolink() function of src/timezone/zic.c.

--
Regards,
Man Zeng
www.openhalo.org

Attachments:

zic_file_leak_fix.diffapplication/octet-stream; charset=gb18030; name=zic_file_leak_fix.diffDownload+1-0
#2zengman
zengman@halodbtech.com
In reply to: zengman (#1)
Re: [Patch] timezone/zic.c: Fix file handle leak in dolink()

Furthermore, I noticed that some of the test code in `contrib/pg_trgm/trgm_regexp.c` does not check the return value of the `fopen()` call.
I'm not sure if it's necessary to make the modification.

--
Regards,
Man Zeng
www.openhalo.org

Attachments:

t52979_2
pg_trgm-add-fopen-null-check.diffapplication/octet-stream; charset=ISO-8859-1; name=pg_trgm-add-fopen-null-check.diffDownload+6-0
#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: zengman (#1)
Re: [Patch] timezone/zic.c: Fix file handle leak in dolink()

"=?gb18030?B?emVuZ21hbg==?=" <zengman@halodbtech.com> writes:

I noticed a small issue and made a tiny patch to fix it ¡ª it addresses a file handle leak in the dolink() function of src/timezone/zic.c.

Huh? The program is going to exit() two lines further down.
What's the point of closing here?

Even if there were a plausible argument for issuing close(),
I wouldn't care to diverge from upstream zic. If you like
you can go try to persuade the tzdb crew that this is a
useful change.

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: zengman (#2)
Re: [Patch] timezone/zic.c: Fix file handle leak in dolink()

"=?ISO-8859-1?B?emVuZ21hbg==?=" <zengman@halodbtech.com> writes:

Furthermore, I noticed that some of the test code in `contrib/pg_trgm/trgm_regexp.c` does not check the return value of the `fopen()` call.
I'm not sure if it's necessary to make the modification.

Probably not worth the trouble. This is barely even debug-grade
code, seeing that there's no provision to change the target file
name. It's clearly not meant for use in unfriendly environments.

regards, tom lane

#5zengman
zengman@halodbtech.com
In reply to: Tom Lane (#4)
Re: [Patch] timezone/zic.c: Fix file handle leak in dolink()

Got it, thank you for your guidance.

--
Regards,
Man Zeng
www.openhalo.org