Plug more memory leaks when reloading config file.
authorRobert Haas <rhaas@postgresql.org>
Tue, 21 Jan 2014 14:41:40 +0000 (09:41 -0500)
committerRobert Haas <rhaas@postgresql.org>
Tue, 21 Jan 2014 14:48:14 +0000 (09:48 -0500)
Commit 138184adc5f7c60c184972e4d23f8cdb32aed77d plugged some but not
all of the leaks from commit 2a0c81a12c7e6c5ac1557b0f1f4a581f23fd4ca7.
This tightens things up some more.

Amit Kapila, per an observation by Tom Lane

src/backend/utils/misc/guc-file.l

index c5ca4a40742b3a8fdd4bb555731a1032af3de130..c91e82bedfdfdbc73923b771c5ec78130643e057 100644 (file)
@@ -437,18 +437,22 @@ ParseConfigFile(const char *config_file, const char *calling_file, bool strict,
                    (errcode_for_file_access(),
                     errmsg("could not open configuration file \"%s\": %m",
                            abs_path)));
-           return false;
+           OK = false;
+           goto cleanup;
        }
 
        ereport(LOG,
                (errmsg("skipping missing configuration file \"%s\"",
                        abs_path)));
-       return OK;
+       OK = true;
+       goto cleanup;
    }
 
    OK = ParseConfigFp(fp, abs_path, depth, elevel, head_p, tail_p);
 
-   FreeFile(fp);
+cleanup:
+   if (fp)
+       FreeFile(fp);
    pfree(abs_path);
 
    return OK;
@@ -716,7 +720,8 @@ ParseConfigDirectory(const char *includedir,
                (errcode_for_file_access(),
                 errmsg("could not open configuration directory \"%s\": %m",
                        directory)));
-       return false;
+       status = false;
+       goto cleanup;
    }
 
    /*
@@ -771,7 +776,8 @@ ParseConfigDirectory(const char *includedir,
                    (errcode_for_file_access(),
                     errmsg("could not stat file \"%s\": %m",
                            filename)));
-           return false;
+           status = false;
+           goto cleanup;
        }
    }
 
@@ -792,7 +798,9 @@ ParseConfigDirectory(const char *includedir,
    status = true;
 
 cleanup:
-   FreeDir(d);
+   if (d)
+       FreeDir(d);
+   pfree(directory);
    return status;
 }