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
This commit is contained in:
parent
bf227926d2
commit
f1e9f6bbfa
@ -55,7 +55,7 @@ rmtree(const char *path, bool rmtopdir)
|
|||||||
bool result = true;
|
bool result = true;
|
||||||
size_t dirnames_size = 0;
|
size_t dirnames_size = 0;
|
||||||
size_t dirnames_capacity = 8;
|
size_t dirnames_capacity = 8;
|
||||||
char **dirnames = palloc(sizeof(char *) * dirnames_capacity);
|
char **dirnames;
|
||||||
|
|
||||||
dir = OPENDIR(path);
|
dir = OPENDIR(path);
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
@ -64,6 +64,8 @@ rmtree(const char *path, bool rmtopdir)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dirnames = (char **) palloc(sizeof(char *) * dirnames_capacity);
|
||||||
|
|
||||||
while (errno = 0, (de = readdir(dir)))
|
while (errno = 0, (de = readdir(dir)))
|
||||||
{
|
{
|
||||||
if (strcmp(de->d_name, ".") == 0 ||
|
if (strcmp(de->d_name, ".") == 0 ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user