Skip to content

Commit 66398d4

Browse files
committed
- Fix memleak
1 parent 67206a2 commit 66398d4

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

main/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include "php_ticks.h"
8484
#include "php_logos.h"
8585
#include "php_streams.h"
86+
#include "php_open_temporary_file.h"
8687

8788
#include "SAPI.h"
8889
#include "rfc1867.h"
@@ -1852,6 +1853,7 @@ void php_module_shutdown(TSRMLS_D)
18521853
#endif
18531854

18541855
php_output_shutdown();
1856+
php_shutdown_temporary_directory();
18551857

18561858
module_initialized = 0;
18571859

main/php_open_temporary_file.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,22 @@ static int php_do_open_temporary_file(const char *path, const char *pfx, char **
148148
}
149149
/* }}} */
150150

151+
/* Cache the chosen temporary directory. */
152+
static char* temporary_directory;
153+
154+
PHPAPI void php_shutdown_temporary_directory()
155+
{
156+
if (temporary_directory) {
157+
free(temporary_directory);
158+
temporary_directory = NULL;
159+
}
160+
}
161+
151162
/*
152163
* Determine where to place temporary files.
153164
*/
154165
PHPAPI const char* php_get_temporary_directory(void)
155166
{
156-
/* Cache the chosen temporary directory. */
157-
static char* temporary_directory;
158-
159167
/* Did we determine the temporary directory already? */
160168
if (temporary_directory) {
161169
return temporary_directory;

main/php_open_temporary_file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ BEGIN_EXTERN_C()
2525
PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC);
2626
PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC);
2727
PHPAPI const char *php_get_temporary_directory(void);
28+
PHPAPI void php_shutdown_temporary_directory();
2829
END_EXTERN_C()
2930

3031
#endif /* PHP_OPEN_TEMPORARY_FILE_H */

0 commit comments

Comments
 (0)