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

Commit3e2c22c

Browse files
ildusAlexander Korotkov
authored and
Alexander Korotkov
committed
Fix possible segfault in pg_stat_wait_get_history
1 parent62b5052 commit3e2c22c

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

‎contrib/pg_stat_wait/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ include $(top_builddir)/src/Makefile.global
1919
include$(top_srcdir)/contrib/contrib-global.mk
2020
endif
2121

22-
check:regresscheck
22+
check:isolationcheck
2323

2424
submake-regress:
2525
$(MAKE) -C$(top_builddir)/src/test/regress all

‎contrib/pg_stat_wait/collector.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include"pg_stat_wait.h"
2222

23-
CollectorShmqHeader*hdr;
23+
CollectorShmqHeader*hdr=NULL;
2424

2525
staticvoid*pgsw;
2626
shm_toc*toc;
@@ -52,13 +52,18 @@ CollectorShmemSize(void)
5252
returnsize;
5353
}
5454

55-
void
56-
AllocateCollectorMem(void)
55+
CollectorShmqHeader*
56+
GetCollectorMem(boolinit)
5757
{
5858
boolfound;
5959
Sizesegsize=CollectorShmemSize();
6060

6161
pgsw=ShmemInitStruct("pg_stat_wait",segsize,&found);
62+
if (!init&& !found)
63+
{
64+
ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
65+
errmsg("A collector memory wasn't initialized yet")));
66+
}
6267

6368
if (!found)
6469
{
@@ -76,6 +81,7 @@ AllocateCollectorMem(void)
7681
toc=shm_toc_attach(PG_STAT_WAIT_MAGIC,pgsw);
7782
hdr=shm_toc_lookup(toc,0);
7883
}
84+
returnhdr;
7985
}
8086

8187
void

‎contrib/pg_stat_wait/pg_stat_wait.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ PG_MODULE_MAGIC;
1818
void_PG_init(void);
1919
void_PG_fini(void);
2020

21-
externCollectorShmqHeader*hdr;
2221
externshm_toc*toc;
2322

2423
staticshmem_startup_hook_typeprev_shmem_startup_hook=NULL;
@@ -35,7 +34,7 @@ pgsw_shmem_startup(void)
3534
if (prev_shmem_startup_hook)
3635
prev_shmem_startup_hook();
3736

38-
AllocateCollectorMem();
37+
GetCollectorMem(true);
3938
}
4039
}
4140

@@ -582,13 +581,16 @@ PG_FUNCTION_INFO_V1(pg_stat_wait_get_history);
582581
Datum
583582
pg_stat_wait_get_history(PG_FUNCTION_ARGS)
584583
{
585-
History*observations;
586-
FuncCallContext*funcctx;
584+
History*observations;
585+
FuncCallContext*funcctx;
586+
CollectorShmqHeader*hdr;
587587

588588
if (!WaitsHistoryOn)
589589
ereport(ERROR, (errcode(ERRCODE_CONFIG_FILE_ERROR),
590590
errmsg("Waits history turned off")));
591591

592+
hdr=GetCollectorMem(false);
593+
592594
if (SRF_IS_FIRSTCALL())
593595
{
594596
shm_mq*mq;

‎contrib/pg_stat_wait/pg_stat_wait.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extern PGDLLIMPORT bool historySkipLatch;
7575

7676

7777
SizeCollectorShmemSize(void);
78-
voidAllocateCollectorMem(void);
78+
CollectorShmqHeader*GetCollectorMem(boolinit);
7979
voidRegisterWaitsCollector(void);
8080
voidAllocHistory(History*,int);
8181
intGetCurrentWaitsState(PGPROC*,HistoryItem*,int);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp