git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bf22792)
Avoid memory leak in rmtree() when path cannot be opened
2023年7月31日 02:36:44 +0000 (11:36 +0900)
2023年7月31日 02:36:44 +0000 (11:36 +0900)
An allocation done for the directory names to recurse into for their
deletion was done before OPENDIR(), so, assuming that a failure happens,
this could leak a bit of memory.

Author: Ranier Vilela
Reviewed-by: Daniel Gustafsson
Discussion: https://postgr.es/m/CAEudQAoN3-2ZKBALThnEk_q2hu8En5A0WG9O+5siJTQKVZzoWQ@mail.gmail.com


diff --git a/src/common/rmtree.c b/src/common/rmtree.c
index cd99d3f4719b260ec367a7d4dd1e067319f11a35..fdc3709321894ea3a6319ae8c542e8f804c7f9ae 100644 (file)
--- a/src/common/rmtree.c
+++ b/src/common/rmtree.c
@@ -55,7 +55,7 @@ rmtree(const char *path, bool rmtopdir)
bool result = true;
size_t dirnames_size = 0;
size_t dirnames_capacity = 8;
- char **dirnames = palloc(sizeof(char *) * dirnames_capacity);
+ char **dirnames;
dir = OPENDIR(path);
if (dir == NULL)
@@ -64,6 +64,8 @@ rmtree(const char *path, bool rmtopdir)
return false;
}
+ dirnames = (char **) palloc(sizeof(char *) * dirnames_capacity);
+
while (errno = 0, (de = readdir(dir)))
{
if (strcmp(de->d_name, ".") == 0 ||
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /