Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 04cf0bf

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 schema or a database (or just a single-entry list for the non-parallel case with the database name), the list is allocated and built on-the-fly for each database processed, leaking after one database-level reindex is done. This accumulates leaks when processing all databases, and could become a visible issue with thousands of relations. This is fixed by introducing a new routine in simple_list.c to free all the elements in a simple list made of strings or OIDs. The header of the 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 interface simple. Per report from coverity for an issue introduced by 5ab892c, and valgrind complains about the leak as well. The idea to introduce a new routine in simple_list.c is from Tom Lane. Author: Michael Paquier Reviewed-by: Tom Lane
1 parent 3420851 commit 04cf0bf

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
extern void simple_oid_list_append(SimpleOidList *list, Oid val);
4848
extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
49+
extern void simple_oid_list_destroy(SimpleOidList *list);
4950

5051
extern void simple_string_list_append(SimpleStringList *list, const char *val);
5152
extern bool simple_string_list_member(SimpleStringList *list, const char *val);
53+
extern void simple_string_list_destroy(SimpleStringList *list);
5254

5355
extern const char *simple_string_list_not_touched(SimpleStringList *list);
5456

0 commit comments

Comments
 (0)