mirror of
https://github.com/php/php-src.git
synced 2026-03-26 17:22:15 +01:00
Fixed memory leaks
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user