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

Commit88dc6fa

Browse files
committed
foreach() and list_delete() don't mix.
Fix crash when releasing duplicate entries in the encoding conversion cachelist, caused by releasing the current entry of the list being chased byforeach(). We have a standard idiom for handling such cases, but thisloop wasn't using it.This got broken in my recent rewrite of GUC assign hooks. Not sure howI missed this when testing the modified code, but I did. Per report fromPeter.
1 parentd2f60a3 commit88dc6fa

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

‎src/backend/utils/mb/mbutils.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ SetClientEncoding(int encoding)
189189
intcurrent_server_encoding;
190190
boolfound;
191191
ListCell*lc;
192+
ListCell*prev;
193+
ListCell*next;
192194

193195
if (!PG_VALID_FE_ENCODING(encoding))
194196
return-1;
@@ -222,10 +224,13 @@ SetClientEncoding(int encoding)
222224
* leak memory.
223225
*/
224226
found= false;
225-
foreach(lc,ConvProcList)
227+
prev=NULL;
228+
for (lc=list_head(ConvProcList);lc;lc=next)
226229
{
227230
ConvProcInfo*convinfo= (ConvProcInfo*)lfirst(lc);
228231

232+
next=lnext(lc);
233+
229234
if (convinfo->s_encoding==current_server_encoding&&
230235
convinfo->c_encoding==encoding)
231236
{
@@ -240,10 +245,13 @@ SetClientEncoding(int encoding)
240245
else
241246
{
242247
/* Duplicate entry, release it */
243-
ConvProcList=list_delete_ptr(ConvProcList,convinfo);
248+
ConvProcList=list_delete_cell(ConvProcList,lc,prev);
244249
pfree(convinfo);
250+
continue;/* prev mustn't advance */
245251
}
246252
}
253+
254+
prev=lc;
247255
}
248256

249257
if (found)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp