Skip to content

Commit c117548

Browse files
author
Julien Pauli
committed
Fix for #66048
1 parent 473ec53 commit c117548

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

Diff for: NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed bug #69566 (Conditional jump or move depends on uninitialised value
77
in extension trait). (jbboehr at gmail dot com)
8+
. Fixed bug #66048 (temp. directory is cached during multiple requests).
9+
(Julien)
810

911
- Iconv:
1012
. Fixed bug #48147 (iconv with //IGNORE cuts the string). (Stas)

Diff for: main/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1798,7 +1798,7 @@ void php_request_shutdown(void *dummy)
17981798
}
17991799
} zend_end_try();
18001800

1801-
/* 7.5 free last error information */
1801+
/* 7.5 free last error information and temp dir */
18021802
if (PG(last_error_message)) {
18031803
free(PG(last_error_message));
18041804
PG(last_error_message) = NULL;
@@ -1807,6 +1807,7 @@ void php_request_shutdown(void *dummy)
18071807
free(PG(last_error_file));
18081808
PG(last_error_file) = NULL;
18091809
}
1810+
php_shutdown_temporary_directory();
18101811

18111812
/* 7. Shutdown scanner/executor/compiler and restore ini entries */
18121813
zend_deactivate(TSRMLS_C);
@@ -2403,7 +2404,6 @@ void php_module_shutdown(TSRMLS_D)
24032404
#endif
24042405

24052406
php_output_shutdown();
2406-
php_shutdown_temporary_directory();
24072407

24082408
module_initialized = 0;
24092409

Diff for: main/php_open_temporary_file.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static char* temporary_directory;
181181
PHPAPI void php_shutdown_temporary_directory(void)
182182
{
183183
if (temporary_directory) {
184-
free(temporary_directory);
184+
efree(temporary_directory);
185185
temporary_directory = NULL;
186186
}
187187
}
@@ -202,10 +202,10 @@ PHPAPI const char* php_get_temporary_directory(TSRMLS_D)
202202
if (sys_temp_dir) {
203203
int len = strlen(sys_temp_dir);
204204
if (len >= 2 && sys_temp_dir[len - 1] == DEFAULT_SLASH) {
205-
temporary_directory = zend_strndup(sys_temp_dir, len - 1);
205+
temporary_directory = estrndup(sys_temp_dir, len - 1);
206206
return temporary_directory;
207207
} else if (len >= 1 && sys_temp_dir[len - 1] != DEFAULT_SLASH) {
208-
temporary_directory = zend_strndup(sys_temp_dir, len);
208+
temporary_directory = estrndup(sys_temp_dir, len);
209209
return temporary_directory;
210210
}
211211
}
@@ -222,9 +222,9 @@ PHPAPI const char* php_get_temporary_directory(TSRMLS_D)
222222
DWORD len = GetTempPath(sizeof(sTemp),sTemp);
223223
assert(0 < len); /* should *never* fail! */
224224
if (sTemp[len - 1] == DEFAULT_SLASH) {
225-
temporary_directory = zend_strndup(sTemp, len - 1);
225+
temporary_directory = estrndup(sTemp, len - 1);
226226
} else {
227-
temporary_directory = zend_strndup(sTemp, len);
227+
temporary_directory = estrndup(sTemp, len);
228228
}
229229
return temporary_directory;
230230
}
@@ -236,9 +236,9 @@ PHPAPI const char* php_get_temporary_directory(TSRMLS_D)
236236
int len = strlen(s);
237237

238238
if (s[len - 1] == DEFAULT_SLASH) {
239-
temporary_directory = zend_strndup(s, len - 1);
239+
temporary_directory = estrndup(s, len - 1);
240240
} else {
241-
temporary_directory = zend_strndup(s, len);
241+
temporary_directory = estrndup(s, len);
242242
}
243243

244244
return temporary_directory;
@@ -247,12 +247,12 @@ PHPAPI const char* php_get_temporary_directory(TSRMLS_D)
247247
#ifdef P_tmpdir
248248
/* Use the standard default temporary directory. */
249249
if (P_tmpdir) {
250-
temporary_directory = strdup(P_tmpdir);
250+
temporary_directory = estrdup(P_tmpdir);
251251
return temporary_directory;
252252
}
253253
#endif
254254
/* Shouldn't ever(!) end up here ... last ditch default. */
255-
temporary_directory = strdup("/tmp");
255+
temporary_directory = estrndup("/tmp", sizeof("/tmp"));
256256
return temporary_directory;
257257
#endif
258258
}

0 commit comments

Comments
 (0)