Skip to content

Commit d367d41

Browse files
committed
Fix file descriptor leaks in pg_upgrade in failure code paths.
1 parent 51c0124 commit d367d41

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

contrib/pg_upgrade/check.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,11 @@ check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster)
515515
PQfinish(conn);
516516
}
517517

518+
if (script)
519+
fclose(script);
520+
518521
if (found)
519522
{
520-
fclose(script);
521523
pg_log(PG_REPORT, "fatal\n");
522524
pg_log(PG_FATAL,
523525
"| Your installation contains \"/contrib/isn\" functions\n"
@@ -616,9 +618,11 @@ check_for_reg_data_type_usage(ClusterInfo *cluster)
616618
PQfinish(conn);
617619
}
618620

621+
if (script)
622+
fclose(script);
623+
619624
if (found)
620625
{
621-
fclose(script);
622626
pg_log(PG_REPORT, "fatal\n");
623627
pg_log(PG_FATAL,
624628
"| Your installation contains one of the reg* data types in\n"

contrib/pg_upgrade/file.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,21 @@ pg_scandir_internal(const char *dirname,
302302
(size_t) ((name_num + 1) * sizeof(struct dirent *)));
303303

304304
if (*namelist == NULL)
305+
{
306+
closedir(dirdesc);
305307
return -1;
308+
}
306309

307310
entrysize = sizeof(struct dirent) - sizeof(direntry->d_name) +
308311
strlen(direntry->d_name) + 1;
309312

310313
(*namelist)[name_num] = (struct dirent *) malloc(entrysize);
311314

312315
if ((*namelist)[name_num] == NULL)
316+
{
317+
closedir(dirdesc);
313318
return -1;
319+
}
314320

315321
memcpy((*namelist)[name_num], direntry, entrysize);
316322

contrib/pg_upgrade/server.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,9 @@ get_major_server_version(ClusterInfo *cluster)
144144
if (fscanf(version_fd, "%63s", cluster->major_version_str) == 0 ||
145145
sscanf(cluster->major_version_str, "%d.%d", &integer_version,
146146
&fractional_version) != 2)
147-
{
148147
pg_log(PG_FATAL, "could not get version from %s\n", datadir);
149-
fclose(version_fd);
150-
return 0;
151-
}
148+
149+
fclose(version_fd);
152150

153151
return (100 * integer_version + fractional_version) * 100;
154152
}

contrib/pg_upgrade/version.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster, bool check_mode)
6262
PQfinish(conn);
6363
}
6464

65+
if (script)
66+
fclose(script);
67+
6568
if (found)
6669
{
67-
if (!check_mode)
68-
fclose(script);
6970
report_status(PG_WARNING, "warning");
7071
if (check_mode)
7172
pg_log(PG_WARNING, "\n"

contrib/pg_upgrade/version_old_8_3.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ old_8_3_check_for_name_data_type_usage(ClusterInfo *cluster)
8787
PQfinish(conn);
8888
}
8989

90+
if (script)
91+
fclose(script);
92+
9093
if (found)
9194
{
92-
fclose(script);
9395
pg_log(PG_REPORT, "fatal\n");
9496
pg_log(PG_FATAL,
9597
"| Your installation contains the \"name\" data type in\n"
@@ -175,9 +177,11 @@ old_8_3_check_for_tsquery_usage(ClusterInfo *cluster)
175177
PQfinish(conn);
176178
}
177179

180+
if (script)
181+
fclose(script);
182+
178183
if (found)
179184
{
180-
fclose(script);
181185
pg_log(PG_REPORT, "fatal\n");
182186
pg_log(PG_FATAL,
183187
"| Your installation contains the \"tsquery\" data type.\n"
@@ -314,10 +318,11 @@ old_8_3_rebuild_tsvector_tables(ClusterInfo *cluster, bool check_mode)
314318
PQfinish(conn);
315319
}
316320

321+
if (script)
322+
fclose(script);
323+
317324
if (found)
318325
{
319-
if (!check_mode)
320-
fclose(script);
321326
report_status(PG_WARNING, "warning");
322327
if (check_mode)
323328
pg_log(PG_WARNING, "\n"
@@ -424,10 +429,11 @@ old_8_3_invalidate_hash_gin_indexes(ClusterInfo *cluster, bool check_mode)
424429
PQfinish(conn);
425430
}
426431

432+
if (script)
433+
fclose(script);
434+
427435
if (found)
428436
{
429-
if (!check_mode)
430-
fclose(script);
431437
report_status(PG_WARNING, "warning");
432438
if (check_mode)
433439
pg_log(PG_WARNING, "\n"
@@ -553,10 +559,11 @@ old_8_3_invalidate_bpchar_pattern_ops_indexes(ClusterInfo *cluster,
553559
PQfinish(conn);
554560
}
555561

562+
if (script)
563+
fclose(script);
564+
556565
if (found)
557566
{
558-
if (!check_mode)
559-
fclose(script);
560567
report_status(PG_WARNING, "warning");
561568
if (check_mode)
562569
pg_log(PG_WARNING, "\n"
@@ -672,7 +679,8 @@ old_8_3_create_sequence_script(ClusterInfo *cluster)
672679

673680
PQfinish(conn);
674681
}
675-
if (found)
682+
683+
if (script)
676684
fclose(script);
677685

678686
check_ok();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy