]> granicus.if.org Git - php/commitdiff
Fixed memory leaks
authorDmitry Stogov <dmitry@zend.com>
Tue, 6 May 2014 11:18:17 +0000 (15:18 +0400)
committerDmitry Stogov <dmitry@zend.com>
Tue, 6 May 2014 11:18:17 +0000 (15:18 +0400)
ext/ftp/ftp.c
ext/ftp/ftp.h
ext/ftp/php_ftp.c

index 2047193a94ec92e3888ad39e5f4119ec2a50ca5b..a6b1c7ad5e8a614bd10f83fac3b2d029e848f492 100644 (file)
@@ -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) {
index 2759ce2af5fa0dbf73ef5c112127e7139cd47ee1..6b2b1ae1922e47e4e12f04e6766289f2be4831e6 100644 (file)
@@ -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
index 47032ddd9348559c87a77d317faa79c1dd3b3104..5f0e3a2646512ae2e0ae681bda1479018a8041c5 100644 (file)
@@ -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) {