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

Commitb6dd127

Browse files
committed
Ensure BackgroundWorker struct contents are well-defined.
Coverity complained because bgw.bgw_extra wasn't being filled in byApplyLauncherRegister(). The most future-proof fix is to memset thewhole BackgroundWorker struct to zeroes. While at it, let's apply thesame coding rule to other places that set up BackgroundWorker structs;four out of five had the same or related issues.
1 parentc7d225e commitb6dd127

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

‎src/backend/access/transam/parallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ LaunchParallelWorkers(ParallelContext *pcxt)
435435
oldcontext=MemoryContextSwitchTo(TopTransactionContext);
436436

437437
/* Configure a worker. */
438+
memset(&worker,0,sizeof(worker));
438439
snprintf(worker.bgw_name,BGW_MAXLEN,"parallel worker for PID %d",
439440
MyProcPid);
440441
worker.bgw_flags=
@@ -446,7 +447,6 @@ LaunchParallelWorkers(ParallelContext *pcxt)
446447
sprintf(worker.bgw_function_name,"ParallelWorkerMain");
447448
worker.bgw_main_arg=UInt32GetDatum(dsm_segment_handle(pcxt->seg));
448449
worker.bgw_notify_pid=MyProcPid;
449-
memset(&worker.bgw_extra,0,BGW_EXTRALEN);
450450

451451
/*
452452
* Start workers.

‎src/backend/replication/logical/launcher.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ logicalrep_worker_launch(Oid dbid, Oid subid, const char *subname, Oid userid,
291291
LWLockRelease(LogicalRepWorkerLock);
292292

293293
/* Register the new dynamic worker. */
294+
memset(&bgw,0,sizeof(bgw));
294295
bgw.bgw_flags=BGWORKER_SHMEM_ACCESS |
295296
BGWORKER_BACKEND_DATABASE_CONNECTION;
296297
bgw.bgw_start_time=BgWorkerStart_RecoveryFinished;
@@ -560,6 +561,10 @@ ApplyLauncherShmemSize(void)
560561
returnsize;
561562
}
562563

564+
/*
565+
* ApplyLauncherRegister
566+
*Register a background worker running the logical replication launcher.
567+
*/
563568
void
564569
ApplyLauncherRegister(void)
565570
{
@@ -568,6 +573,7 @@ ApplyLauncherRegister(void)
568573
if (max_logical_replication_workers==0)
569574
return;
570575

576+
memset(&bgw,0,sizeof(bgw));
571577
bgw.bgw_flags=BGWORKER_SHMEM_ACCESS |
572578
BGWORKER_BACKEND_DATABASE_CONNECTION;
573579
bgw.bgw_start_time=BgWorkerStart_RecoveryFinished;

‎src/test/modules/test_shm_mq/setup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ setup_background_workers(int nworkers, dsm_segment *seg)
213213
PointerGetDatum(wstate));
214214

215215
/* Configure a worker. */
216+
memset(&worker,0,sizeof(worker));
216217
worker.bgw_flags=BGWORKER_SHMEM_ACCESS;
217218
worker.bgw_start_time=BgWorkerStart_ConsistentState;
218219
worker.bgw_restart_time=BGW_NEVER_RESTART;

‎src/test/modules/worker_spi/worker_spi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ _PG_init(void)
343343
NULL);
344344

345345
/* set up common data for all our workers */
346+
memset(&worker,0,sizeof(worker));
346347
worker.bgw_flags=BGWORKER_SHMEM_ACCESS |
347348
BGWORKER_BACKEND_DATABASE_CONNECTION;
348349
worker.bgw_start_time=BgWorkerStart_RecoveryFinished;
@@ -375,6 +376,7 @@ worker_spi_launch(PG_FUNCTION_ARGS)
375376
BgwHandleStatusstatus;
376377
pid_tpid;
377378

379+
memset(&worker,0,sizeof(worker));
378380
worker.bgw_flags=BGWORKER_SHMEM_ACCESS |
379381
BGWORKER_BACKEND_DATABASE_CONNECTION;
380382
worker.bgw_start_time=BgWorkerStart_RecoveryFinished;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp