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

Commit89e434b

Browse files
committed
Fix coding rules violations in walreceiver.c
1. Since commitb1a9bad we had pstrdup() inside aspinlock-protected critical section; reported by Andreas Seltenreich.Turn those into strlcpy() to stack-allocated variables instead.Backpatch to 9.6.2. Since commit9ed551e we had a pfree() uselessly inside aspinlock-protected critical section. Tom Lane noticed in code review.Move down. Backpatch to 9.6.3. Since commit6423390 we had GetCurrentTimestamp() (a kernelcall) inside a spinlock-protected critical section. Tom Lane noticed incode review. Move it up. Backpatch to 9.2.4. Since commit1bb2558 we did elog(PANIC) while holding spinlock.Tom Lane noticed in code review. Release spinlock before dying.Backpatch to 9.2.Discussion:https://postgr.es/m/87h8vhtgj2.fsf@ansel.ydns.eu
1 parentf41bd4c commit89e434b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

‎src/backend/replication/walreceiver.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ WalReceiverMain(void)
196196
boolfirst_stream;
197197
WalRcvData*walrcv=WalRcv;
198198
TimestampTzlast_recv_timestamp;
199+
TimestampTznow;
199200
boolping_sent;
200201
char*err;
201202

@@ -205,6 +206,8 @@ WalReceiverMain(void)
205206
*/
206207
Assert(walrcv!=NULL);
207208

209+
now=GetCurrentTimestamp();
210+
208211
/*
209212
* Mark walreceiver as running in shared memory.
210213
*
@@ -235,6 +238,7 @@ WalReceiverMain(void)
235238
caseWALRCV_RESTARTING:
236239
default:
237240
/* Shouldn't happen */
241+
SpinLockRelease(&walrcv->mutex);
238242
elog(PANIC,"walreceiver still running according to shared memory state");
239243
}
240244
/* Advertise our PID so that the startup process can kill us */
@@ -249,7 +253,8 @@ WalReceiverMain(void)
249253
startpointTLI=walrcv->receiveStartTLI;
250254

251255
/* Initialise to a sanish value */
252-
walrcv->lastMsgSendTime=walrcv->lastMsgReceiptTime=walrcv->latestWalEndTime=GetCurrentTimestamp();
256+
walrcv->lastMsgSendTime=
257+
walrcv->lastMsgReceiptTime=walrcv->latestWalEndTime=now;
253258

254259
SpinLockRelease(&walrcv->mutex);
255260

@@ -308,13 +313,13 @@ WalReceiverMain(void)
308313
SpinLockAcquire(&walrcv->mutex);
309314
memset(walrcv->conninfo,0,MAXCONNINFO);
310315
if (tmp_conninfo)
311-
{
312316
strlcpy((char*)walrcv->conninfo,tmp_conninfo,MAXCONNINFO);
313-
pfree(tmp_conninfo);
314-
}
315317
walrcv->ready_to_display= true;
316318
SpinLockRelease(&walrcv->mutex);
317319

320+
if (tmp_conninfo)
321+
pfree(tmp_conninfo);
322+
318323
first_stream= true;
319324
for (;;)
320325
{
@@ -1390,8 +1395,8 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
13901395
TimestampTzlast_receipt_time;
13911396
XLogRecPtrlatest_end_lsn;
13921397
TimestampTzlatest_end_time;
1393-
char*slotname;
1394-
char*conninfo;
1398+
charslotname[NAMEDATALEN];
1399+
charconninfo[MAXCONNINFO];
13951400

13961401
/* Take a lock to ensure value consistency */
13971402
SpinLockAcquire(&WalRcv->mutex);
@@ -1406,8 +1411,8 @@ pg_stat_get_wal_receiver(PG_FUNCTION_ARGS)
14061411
last_receipt_time=WalRcv->lastMsgReceiptTime;
14071412
latest_end_lsn=WalRcv->latestWalEnd;
14081413
latest_end_time=WalRcv->latestWalEndTime;
1409-
slotname=pstrdup(WalRcv->slotname);
1410-
conninfo=pstrdup(WalRcv->conninfo);
1414+
strlcpy(slotname, (char*)WalRcv->slotname,sizeof(slotname));
1415+
strlcpy(conninfo, (char*)WalRcv->conninfo,sizeof(conninfo));
14111416
SpinLockRelease(&WalRcv->mutex);
14121417

14131418
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp