Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4b65269

Browse files
committed
Fix memory leaks from incorrect strsep() uses
Commit5d2e1cc introduced some strsep() uses, but it did thememory management wrong in some cases. We need to keep a separatepointer to the allocate memory so that we can free it later, becausestrsep() advances the pointer we pass to it, and it at the end itwill be NULL, so any free() calls won't do anything.(This fixes two of the four places changed in commit5d2e1cc. Theother two don't have this problem.)Reported-by: Alexander Lakhin <exclusion@gmail.com>Discussion:https://www.postgresql.org/message-id/flat/79692bf9-17d3-41e6-b9c9-fc8c3944222a@eisentraut.org
1 parent24a36f9 commit4b65269

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

‎src/common/logging.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ pg_logging_init(const char *argv0)
120120
if (colors)
121121
{
122122
char*token;
123+
char*cp=colors;
123124

124-
while ((token=strsep(&colors,":")))
125+
while ((token=strsep(&cp,":")))
125126
{
126127
char*e=strchr(token,'=');
127128

‎src/test/regress/pg_regress.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,17 @@ free_stringlist(_stringlist **listhead)
233233
staticvoid
234234
split_to_stringlist(constchar*s,constchar*delim,_stringlist**listhead)
235235
{
236-
char*sc=pg_strdup(s);
237236
char*token;
237+
char*sc;
238+
char*tofree;
239+
240+
tofree=sc=pg_strdup(s);
238241

239242
while ((token=strsep(&sc,delim)))
240243
{
241244
add_stringlist_item(listhead,token);
242245
}
243-
free(sc);
246+
free(tofree);
244247
}
245248

246249
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp