From: Dmitry Stogov Date: Tue, 6 May 2014 11:18:17 +0000 (+0400) Subject: Fixed memory leaks X-Git-Tag: POST_PHPNG_MERGE~402 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ebe024fd785fecfa23ab9e31754a3e2cd1d36bd7;p=php Fixed memory leaks --- diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 2047193a94..a6b1c7ad5e 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 2759ce2af5..6b2b1ae192 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 47032ddd93..5f0e3a2646 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) {