]> granicus.if.org Git - php/commitdiff
- fix leak in statName and statIndex
authorPierre Joye <pajoye@php.net>
Mon, 30 Oct 2006 17:28:29 +0000 (17:28 +0000)
committerPierre Joye <pajoye@php.net>
Mon, 30 Oct 2006 17:28:29 +0000 (17:28 +0000)
- use zip_locate_name instead of zip_stat in setCommentName (faster and
  work around for a possible bug)

ext/zip/php_zip.c

index e89c31bd45909af01db0fea75c5f4786dd86b483..63ddc7445fdffbe577a50e8c8f6c2d335dd2406e 100644 (file)
@@ -183,7 +183,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file TSRMLS_D
 #define RETURN_SB(sb) \
        { \
                array_init(return_value); \
-               add_assoc_string(return_value, "name", estrdup((sb)->name), 0); \
+               add_assoc_string(return_value, "name", (char *)(sb)->name, 1); \
                add_assoc_long(return_value, "index", (long) (sb)->index); \
                add_assoc_long(return_value, "crc", (long) (sb)->crc); \
                add_assoc_long(return_value, "size", (long) (sb)->size); \
@@ -1250,7 +1250,7 @@ ZIPARCHIVE_METHOD(setCommentName)
        zval *this = getThis();
        int comment_len, name_len;
        char * comment, *name;
-       struct zip_stat sb;
+       int idx;
 
        if (!this) {
                RETURN_FALSE;
@@ -1263,9 +1263,11 @@ ZIPARCHIVE_METHOD(setCommentName)
                return;
        }
 
-
-       PHP_ZIP_STAT_PATH(intern, name, name_len, 0, sb);
-       PHP_ZIP_SET_FILE_COMMENT(intern, sb.index, comment, comment_len);
+       idx = zip_name_locate(intern, name, 0);
+       if (idx < 0) {
+               RETURN_FALSE;
+       }
+       PHP_ZIP_SET_FILE_COMMENT(intern, idx, comment, comment_len);
 }
 /* }}} */