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

Commit04cf0bf

Browse files
committed
Fix memory leak coming from simple lists built in reindexdb
When building a list of relations for a parallel processing of a schemaor a database (or just a single-entry list for the non-parallel casewith the database name), the list is allocated and built on-the-fly foreach database processed, leaking after one database-level reindex isdone. This accumulates leaks when processing all databases, and couldbecome a visible issue with thousands of relations.This is fixed by introducing a new routine in simple_list.c to free allthe elements in a simple list made of strings or OIDs. The header ofthe list may be using a variable declaration or an allocated pointer,so we don't have a routine to free this part to keep the interfacesimple.Per report from coverity for an issue introduced by5ab892c, andvalgrind complains about the leak as well. The idea to introduce a newroutine in simple_list.c is from Tom Lane.Author: Michael PaquierReviewed-by: Tom Lane
1 parent3420851 commit04cf0bf

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

‎src/bin/scripts/reindexdb.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ reindex_one_database(const char *dbname, ReindexType type,
473473
failed= true;
474474

475475
finish:
476+
if (process_list!=user_list)
477+
{
478+
simple_string_list_destroy(process_list);
479+
pg_free(process_list);
480+
}
481+
476482
ParallelSlotsTerminate(slots,concurrentCons);
477483
pfree(slots);
478484

‎src/fe_utils/simple_list.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,44 @@ simple_string_list_member(SimpleStringList *list, const char *val)
9999
return false;
100100
}
101101

102+
/*
103+
* Destroy an OID list
104+
*/
105+
void
106+
simple_oid_list_destroy(SimpleOidList*list)
107+
{
108+
SimpleOidListCell*cell;
109+
110+
cell=list->head;
111+
while (cell!=NULL)
112+
{
113+
SimpleOidListCell*next;
114+
115+
next=cell->next;
116+
pg_free(cell);
117+
cell=next;
118+
}
119+
}
120+
121+
/*
122+
* Destroy a string list
123+
*/
124+
void
125+
simple_string_list_destroy(SimpleStringList*list)
126+
{
127+
SimpleStringListCell*cell;
128+
129+
cell=list->head;
130+
while (cell!=NULL)
131+
{
132+
SimpleStringListCell*next;
133+
134+
next=cell->next;
135+
pg_free(cell);
136+
cell=next;
137+
}
138+
}
139+
102140
/*
103141
* Find first not-touched list entry, if there is one.
104142
*/

‎src/include/fe_utils/simple_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ typedef struct SimpleStringList
4646

4747
externvoidsimple_oid_list_append(SimpleOidList*list,Oidval);
4848
externboolsimple_oid_list_member(SimpleOidList*list,Oidval);
49+
externvoidsimple_oid_list_destroy(SimpleOidList*list);
4950

5051
externvoidsimple_string_list_append(SimpleStringList*list,constchar*val);
5152
externboolsimple_string_list_member(SimpleStringList*list,constchar*val);
53+
externvoidsimple_string_list_destroy(SimpleStringList*list);
5254

5355
externconstchar*simple_string_list_not_touched(SimpleStringList*list);
5456

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp