Skip to content

Commit 984debb

Browse files
michaelpqpull[bot]
authored andcommitted
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 d3c69ee commit 984debb

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)