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

Commitb7fc1dd

Browse files
committed
Fix failure to consider failure cases in GetComboCommandId().
Failure to initially palloc the comboCids array, or to realloc it biggerwhen needed, left combocid's data structures in an inconsistent state thatwould cause trouble if the top transaction continues to execute. Notedwhile examining a user complaint about the amount of memory used for this.(There's not much we can do about that, but it does point up that repallocfailure has a non-negligible chance of occurring here.)In HEAD/9.5, also avoid possible invocation of memcpy() with a null pointerin SerializeComboCIDState; cf commit13bba02.
1 parent3d357b4 commitb7fc1dd

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

‎src/backend/utils/time/combocid.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ GetComboCommandId(CommandId cmin, CommandId cmax)
215215
{
216216
HASHCTLhash_ctl;
217217

218+
/* Make array first; existence of hash table asserts array exists */
219+
comboCids= (ComboCidKeyData*)
220+
MemoryContextAlloc(TopTransactionContext,
221+
sizeof(ComboCidKeyData)*CCID_ARRAY_SIZE);
222+
sizeComboCids=CCID_ARRAY_SIZE;
223+
usedComboCids=0;
224+
218225
memset(&hash_ctl,0,sizeof(hash_ctl));
219226
hash_ctl.keysize=sizeof(ComboCidKeyData);
220227
hash_ctl.entrysize=sizeof(ComboCidEntryData);
@@ -225,12 +232,20 @@ GetComboCommandId(CommandId cmin, CommandId cmax)
225232
CCID_HASH_SIZE,
226233
&hash_ctl,
227234
HASH_ELEM |HASH_FUNCTION |HASH_CONTEXT);
235+
}
236+
237+
/*
238+
* Grow the array if there's not at least one free slot. We must do this
239+
* before possibly entering a new hashtable entry, else failure to
240+
* repalloc would leave a corrupt hashtable entry behind.
241+
*/
242+
if (usedComboCids >=sizeComboCids)
243+
{
244+
intnewsize=sizeComboCids*2;
228245

229246
comboCids= (ComboCidKeyData*)
230-
MemoryContextAlloc(TopTransactionContext,
231-
sizeof(ComboCidKeyData)*CCID_ARRAY_SIZE);
232-
sizeComboCids=CCID_ARRAY_SIZE;
233-
usedComboCids=0;
247+
repalloc(comboCids,sizeof(ComboCidKeyData)*newsize);
248+
sizeComboCids=newsize;
234249
}
235250

236251
/* Lookup or create a hash entry with the desired cmin/cmax */
@@ -249,20 +264,7 @@ GetComboCommandId(CommandId cmin, CommandId cmax)
249264
returnentry->combocid;
250265
}
251266

252-
/*
253-
* We have to create a new combo cid. Check that there's room for it in
254-
* the array, and grow it if there isn't.
255-
*/
256-
if (usedComboCids >=sizeComboCids)
257-
{
258-
/* We need to grow the array */
259-
intnewsize=sizeComboCids*2;
260-
261-
comboCids= (ComboCidKeyData*)
262-
repalloc(comboCids,sizeof(ComboCidKeyData)*newsize);
263-
sizeComboCids=newsize;
264-
}
265-
267+
/* We have to create a new combo cid; we already made room in the array */
266268
combocid=usedComboCids;
267269

268270
comboCids[combocid].cmin=cmin;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp