Commit: ebe024fd785fecfa23ab9e31754a3e2cd1d36bd7
Author: Dmitry Stogov <dmitry@zend.com> Tue, 6 May 2014 15:18:17 +0400
Parents: 70a5e0e42981a2d38c9477741ab3242740034d47
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ebe024fd785fecfa23ab9e31754a3e2cd1d36bd7
Log:
Fixed memory leaks
Changed paths:
M ext/ftp/ftp.c
M ext/ftp/ftp.h
M ext/ftp/php_ftp.c
Diff:
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index 2047193..a6b1c7a 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -537,10 +537,11 @@ ftp_cdup(ftpbuf_t *ftp)
/* {{{ ftp_mkdir
*/
-char*
+zend_string*
ftp_mkdir(ftpbuf_t *ftp, const char *dir)
{
char *mkd, *end;
+ zend_string *ret;
if (ftp == NULL) {
return NULL;
@@ -553,17 +554,16 @@ ftp_mkdir(ftpbuf_t *ftp, const char *dir)
}
/* copy out the dir from response */
if ((mkd = strchr(ftp->inbuf, '"')) == NULL) {
- mkd = estrdup(dir);
- return mkd;
+ return STR_INIT(dir, strlen(dir), 0);
}
if ((end = strrchr(++mkd, '"')) == NULL) {
return NULL;
}
*end = 0;
- mkd = estrdup(mkd);
+ ret = STR_INIT(mkd, end - mkd, 0);
*end = '"';
- return mkd;
+ return ret;
}
/* }}} */
@@ -616,7 +616,7 @@ ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filenam
/* {{{ ftp_alloc
*/
int
-ftp_alloc(ftpbuf_t *ftp, const long size, char **response)
+ftp_alloc(ftpbuf_t *ftp, const long size, zend_string **response)
{
char buffer[64];
@@ -635,7 +635,7 @@ ftp_alloc(ftpbuf_t *ftp, const long size, char **response)
}
if (response) {
- *response = estrdup(ftp->inbuf);
+ *response = STR_INIT(ftp->inbuf, strlen(ftp->inbuf), 0);
}
if (ftp->resp < 200 || ftp->resp >= 300) {
diff --git a/ext/ftp/ftp.h b/ext/ftp/ftp.h
index 2759ce2...6b2b1ae 100644
--- a/ext/ftp/ftp.h
+++ b/ext/ftp/ftp.h
@@ -133,7 +133,7 @@ int ftp_cdup(ftpbuf_t *ftp);
/* creates a directory, return the directory name on success, NULL on error.
* the return value must be freed
*/
-char* ftp_mkdir(ftpbuf_t *ftp, const char *dir);
+zend_string* ftp_mkdir(ftpbuf_t *ftp, const char *dir);
/* removes a directory, return true on success, false on error */
int ftp_rmdir(ftpbuf_t *ftp, const char *dir);
@@ -146,7 +146,7 @@ int ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int fi
* however some servers will not accept STOR or APPE until ALLO is confirmed.
* If response is passed, it is estrdup()ed from ftp->inbuf and must be freed
* or assigned to a zval returned to the user */
-int ftp_alloc(ftpbuf_t *ftp, const long size, char **response);
+int ftp_alloc(ftpbuf_t *ftp, const long size, zend_string **response);
/* returns a NULL-terminated array of filenames in the given path
* or NULL on error. the return array must be freed (but don't
diff --git a/ext/ftp/php_ftp.c b/ext/ftp/php_ftp.c
index 47032dd..5f0e3a2 100644
--- a/ext/ftp/php_ftp.c
+++ b/ext/ftp/php_ftp.c
@@ -553,7 +553,8 @@ PHP_FUNCTION(ftp_mkdir)
{
zval *z_ftp;
ftpbuf_t *ftp;
- char *dir, *tmp;
+ char *dir;
+ zend_string *tmp;
int dir_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &z_ftp, &dir,
&dir_len) == FAILURE) {
@@ -568,7 +569,7 @@ PHP_FUNCTION(ftp_mkdir)
RETURN_FALSE;
}
- RETURN_STRING(tmp);
+ RETURN_STR(tmp);
}
/* }}} */
@@ -629,7 +630,7 @@ PHP_FUNCTION(ftp_alloc)
zval *z_ftp, *zresponse = NULL;
ftpbuf_t *ftp;
long size, ret;
- char *response = NULL;
+ zend_string *response = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &z_ftp, &size,
&zresponse) == FAILURE) {
RETURN_FALSE;
@@ -639,8 +640,9 @@ PHP_FUNCTION(ftp_alloc)
ret = ftp_alloc(ftp, size, zresponse ? &response : NULL);
if (response) {
+ ZVAL_DEREF(zresponse);
zval_dtor(zresponse);
- ZVAL_STRING(zresponse, response);
+ ZVAL_STR(zresponse, response);
}
if (!ret) {