]> granicus.if.org Git - php/commitdiff
fix leak
authorAnatol Belski <ab@php.net>
Fri, 2 Sep 2016 21:31:26 +0000 (23:31 +0200)
committerAnatol Belski <ab@php.net>
Fri, 2 Sep 2016 21:31:26 +0000 (23:31 +0200)
ext/phar/tar.c

index e40739726bcb18017bd090c967141f3fffbdf4dd..8386623b84237973b66e87a2ed4fc3cff4a582c4 100644 (file)
@@ -959,6 +959,8 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
        entry.tar_type = '0';
        entry.phar = phar;
        entry.fp_type = PHAR_MOD;
+       entry.fp = NULL;
+       entry.filename = NULL;
 
        if (phar->is_persistent) {
                if (error) {
@@ -977,6 +979,7 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
                entry.filename_len = sizeof(".phar/alias.txt")-1;
                entry.fp = php_stream_fopen_tmpfile();
                if (entry.fp == NULL) {
+                       efree(entry.filename);
                        spprintf(error, 0, "phar error: unable to create temporary file");
                        return -1;
                }
@@ -984,6 +987,8 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
                        if (error) {
                                spprintf(error, 0, "unable to set alias in tar-based phar \"%s\"", phar->fname);
                        }
+                       php_stream_close(entry.fp);
+                       efree(entry.filename);
                        return EOF;
                }
 
@@ -993,6 +998,8 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
                        if (error) {
                                spprintf(error, 0, "unable to set alias in tar-based phar \"%s\"", phar->fname);
                        }
+                       php_stream_close(entry.fp);
+                       efree(entry.filename);
                        return EOF;
                }
        } else {
@@ -1008,6 +1015,12 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
                                if (error) {
                                        spprintf(error, 0, "unable to access resource to copy stub to new tar-based phar \"%s\"", phar->fname);
                                }
+                               if (entry.fp) {
+                                       php_stream_close(entry.fp);
+                               }
+                               if (entry.filename) {
+                                       efree(entry.filename);
+                               }
                                return EOF;
                        }
                        if (len == -1) {
@@ -1035,6 +1048,12 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
                                if (error) {
                                        spprintf(error, 0, "unable to read resource to copy stub to new tar-based phar \"%s\"", phar->fname);
                                }
+                               if (entry.fp) {
+                                       php_stream_close(entry.fp);
+                               }
+                               if (entry.filename) {
+                                       efree(entry.filename);
+                               }
                                return EOF;
                        }
                        free_user_stub = 1;
@@ -1051,6 +1070,12 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
                        if (free_user_stub) {
                                efree(user_stub);
                        }
+                       if (entry.fp) {
+                               php_stream_close(entry.fp);
+                       }
+                       if (entry.filename) {
+                               efree(entry.filename);
+                       }
                        return EOF;
                }
                pos = user_stub + (pos - tmp);