]> granicus.if.org Git - php/commitdiff
fix mem leaks
authorGreg Beaver <cellog@php.net>
Fri, 8 Feb 2008 01:06:12 +0000 (01:06 +0000)
committerGreg Beaver <cellog@php.net>
Fri, 8 Feb 2008 01:06:12 +0000 (01:06 +0000)
strip trailing slash if present in a directory entry.  This code assumes that
tar_type is directory, as it must be to be a valid directory.

ext/phar/tar.c

index 74f6c4984ef600c7ff5900c01b80ffa66c9fbde5..78b0022cde69754690c6cd52b4df691222df823b 100644 (file)
@@ -184,6 +184,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
                        }
                        php_stream_close(fp);
                        zend_hash_destroy(&myphar->manifest);
+                       myphar->manifest.arBuckets = 0;
                        efree(myphar);
                        return FAILURE;
                }
@@ -201,6 +202,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
                        }
                        php_stream_close(fp);
                        zend_hash_destroy(&myphar->manifest);
+                       myphar->manifest.arBuckets = 0;
                        efree(myphar);
                        return FAILURE;
                }
@@ -214,10 +216,19 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
                        strcpy(name, hdr->prefix);
                        strcat(name, hdr->name);
                        entry.filename_len = strlen(name);
+                       if (name[entry.filename_len - 1] == '/') {
+                               /* some tar programs store directories with trailing slash */
+                               entry.filename_len--;
+                       }
                        entry.filename = estrndup(name, entry.filename_len);
                } else {
                        entry.filename = estrdup(hdr->name);
                        entry.filename_len = strlen(entry.filename);
+                       if (entry.filename[entry.filename_len - 1] == '/') {
+                               /* some tar programs store directories with trailing slash */
+                               entry.filename[entry.filename_len - 1] = '\0';
+                               entry.filename_len--;
+                       }
                }
 
                entry.tar_type = ((old & (hdr->typeflag == 0))?'0':hdr->typeflag);
@@ -246,6 +257,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
                                }
                                php_stream_close(fp);
                                zend_hash_destroy(&myphar->manifest);
+                               myphar->manifest.arBuckets = 0;
                                efree(myphar);
                                return FAILURE;
                        }
@@ -269,6 +281,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
                                }
                                php_stream_close(fp);
                                zend_hash_destroy(&myphar->manifest);
+                               myphar->manifest.arBuckets = 0;
                                efree(myphar);
                                return FAILURE;
                        }
@@ -293,6 +306,7 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
                }
                php_stream_close(fp);
                zend_hash_destroy(&myphar->manifest);
+               myphar->manifest.arBuckets = 0;
                efree(myphar);
                return FAILURE;
        }
@@ -404,7 +418,9 @@ int phar_tar_writeheaders(void *pDest, void *argument TSRMLS_DC)
 
        entry->is_modified = 0;
        if (entry->fp_type == PHAR_MOD && entry->fp != entry->phar->fp && entry->fp != entry->phar->ufp) {
-               php_stream_close(entry->fp);
+               if (!entry->fp_refcount) {
+                       php_stream_close(entry->fp);
+               }
                entry->fp = NULL;
        }
        entry->fp_type = PHAR_FP;