From 81d9a27c47b12ad20e180afb09c6188c8d403f9f Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 20 Apr 2025 23:59:12 +0200 Subject: [PATCH] Fix some leaks in php_scandir Closes GH-18371. --- NEWS | 1 + main/php_scandir.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 55a58a4d8e7..c24fefcc8c6 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ PHP NEWS - Core: . Fixed bug GH-18304 (Changing the properties of a DateInterval through dynamic properties triggers a SegFault). (nielsdos) + . Fix some leaks in php_scandir. (nielsdos) - Filter: . Fixed bug GH-18309 (ipv6 filter integer overflow). (nielsdos) diff --git a/main/php_scandir.c b/main/php_scandir.c index 7d1eb360236..7bf91bdf7f3 100644 --- a/main/php_scandir.c +++ b/main/php_scandir.c @@ -83,7 +83,7 @@ PHPAPI int php_scandir(const char *dirname, struct dirent **namelist[], int (*se newv = (struct dirent **) realloc (vector, vector_size * sizeof (struct dirent *)); if (!newv) { - return -1; + goto fail; } vector = newv; } @@ -113,6 +113,7 @@ fail: free(vector[nfiles]); } free(vector); + closedir(dirp); return -1; } #endif