svn: /php/php-src/branches/PHP_5_3/TSRM/ tsrm_virtual_cwd.c
| From: | Pierre-Alain Joye | Date: | Mon, 19 Oct 2009 23:41:14 +0000 |
| Subject: | svn: /php/php-src/branches/PHP_5_3/TSRM/ tsrm_virtual_cwd.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-60729@lists.php.net to get a copy of this message | ||
pajoye Mon, 19 Oct 2009 23:41:14 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=289781
Log:
- MFH: fix realloc usage
Changed paths:
U php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c
Modified: php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c
===================================================================
--- php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c 2009-10-19 23:38:55 UTC (rev 289780)
+++ php/php-src/branches/PHP_5_3/TSRM/tsrm_virtual_cwd.c 2009-10-19 23:41:14 UTC (rev 289781)
@@ -983,6 +983,7 @@
time_t t;
int ret;
int add_slash;
+ void *tmp;
TSRMLS_FETCH();
if (path_length == 0 || path_length >= MAXPATHLEN-1) {
@@ -1127,7 +1128,16 @@
CWD_STATE_COPY(&old_state, state);
state->cwd_length = path_length;
- state->cwd = (char *) realloc(state->cwd, state->cwd_length+1);
+
+ tmp = realloc(state->cwd, state->cwd_length+1);
+ if (tmp == NULL) {
+#if VIRTUAL_CWD_DEBUG
+ fprintf (stderr, "Out of memory\n");
+#endif
+ return 1;
+ }
+ state->cwd = (char *) tmp;
+
memcpy(state->cwd, resolved_path, state->cwd_length+1);
if (verify_path(state)) {
CWD_STATE_FREE(state);
@@ -1139,7 +1149,15 @@
}
} else {
state->cwd_length = path_length;
- state->cwd = (char *) realloc(state->cwd, state->cwd_length+1);
+ tmp = realloc(state->cwd, state->cwd_length+1);
+ if (tmp == NULL) {
+#if VIRTUAL_CWD_DEBUG
+ fprintf (stderr, "Out of memory\n");
+#endif
+ return 1;
+ }
+ state->cwd = (char *) tmp;
+
memcpy(state->cwd, resolved_path, state->cwd_length+1);
ret = 0;
}