Skip to content

Commit f1e9f6b

Browse files
committed
Avoid memory leak in rmtree() when path cannot be opened
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
1 parent bf22792 commit f1e9f6b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/common/rmtree.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ rmtree(const char *path, bool rmtopdir)
5555
bool result = true;
5656
size_t dirnames_size = 0;
5757
size_t dirnames_capacity = 8;
58-
char **dirnames = palloc(sizeof(char *) * dirnames_capacity);
58+
char **dirnames;
5959

6060
dir = OPENDIR(path);
6161
if (dir == NULL)
@@ -64,6 +64,8 @@ rmtree(const char *path, bool rmtopdir)
6464
return false;
6565
}
6666

67+
dirnames = (char **) palloc(sizeof(char *) * dirnames_capacity);
68+
6769
while (errno = 0, (de = readdir(dir)))
6870
{
6971
if (strcmp(de->d_name, ".") == 0 ||

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