Re: replace strtok()
Peter Eisentraut <peter@eisentraut.org>
From: Peter Eisentraut <peter@eisentraut.org>
To: Alexander Lakhin <exclusion@gmail.com>,
Ranier Vilela <ranier.vf@gmail.com>
Cc: David Steele <david@pgmasters.net>, Michael Paquier
<michael@paquier.xyz>, Tom Lane <tgl@sss.pgh.pa.us>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-10-16T07:42:22Z
Lists: pgsql-hackers
Attachments
- 0001-Fix-memory-leaks-from-incorrect-strsep-uses.patch (text/plain) patch 0001
On 15.10.24 14:00, Alexander Lakhin wrote:
> I also wonder, if other places touched by 5d2e1cc11 need corrections too.
> I played with
> PG_COLOR=always PG_COLORS="error=01;31" .../initdb
>
> and it looks like this free() call in pg_logging_init():
> char *colors = strdup(pg_colors_env);
>
> if (colors)
> {
> ...
> while ((token = strsep(&colors, ":")))
> {
> ...
> }
>
> free(colors);
> }
> gets null in colors.
Yes, this is indeed incorrect. We need to keep a separate pointer to
the start of the string to free later. This matches the example on the
strsep man page (https://man.freebsd.org/cgi/man.cgi?strsep(3)). Patch
attached.
Commits
-
Fix memory leaks from incorrect strsep() uses
- 4b652692e979 18.0 landed
-
Fix strsep() use for SCRAM secrets parsing
- 24a36f91e32d 18.0 landed
-
Replace remaining strtok() with strtok_r()
- 65504b747f3c 18.0 landed
-
Windows replacement for strtok_r()
- 4d130b28727c 18.0 landed
-
Replace some strtok() with strsep()
- 5d2e1cc117b3 18.0 landed
-
Add port/ replacement for strsep()
- 683be87fbba0 18.0 landed