]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix memory leaks found with Clang Static Analyzer. Those could occur when
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 27 Feb 2012 09:52:30 +0000 (18:52 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 27 Feb 2012 12:25:43 +0000 (21:25 +0900)
something error happend.

cpio/cmdline.c
libarchive/archive_read_disk_entry_from_file.c
libarchive/archive_read_support_format_7zip.c
libarchive/archive_read_support_format_xar.c
libarchive/archive_write_set_format_7zip.c
libarchive/archive_write_set_format_xar.c
libarchive/archive_write_set_format_zip.c

index 390aebc8fb850be89b9f9e64967528ab05fe2b8b..438c27cf6a7703d6f91175bbfe50c7e4ab5292d0 100644 (file)
@@ -346,6 +346,7 @@ owner_parse(const char *spec, int *uid, int *gid)
                                snprintf(errbuff, sizeof(errbuff),
                                    "Couldn't lookup user ``%s''", user);
                                errbuff[sizeof(errbuff) - 1] = '\0';
+                               free(user);
                                return (errbuff);
                        }
                }
index cf0499ea146f125b8a5f77216750c97e4cc98832..2c5e9f7c16c96676ac19aca7676cad4b5d2ef0e6 100644 (file)
@@ -698,6 +698,7 @@ setup_xattr(struct archive_read_disk *a, struct archive_entry *entry,
                size = extattr_get_file(accpath, namespace, name, value, size);
 
        if (size == -1) {
+               free(value);
                archive_set_error(&a->archive, errno,
                    "Couldn't read extended attribute");
                return (ARCHIVE_WARN);
index c1bcd6ad8ca3e229154e4274ff4244b2a2ed0ee7..53f138ea9b973527dc9a7633e4f9a10c3f62a315 100644 (file)
@@ -653,19 +653,24 @@ archive_read_format_7zip_read_header(struct archive_read *a,
                 */
                while (zip->entry_bytes_remaining > 0) {
                        const void *buff;
+                       unsigned char *mem;
                        size_t size;
                        int64_t offset;
 
                        r = archive_read_format_7zip_read_data(a, &buff,
                                &size, &offset);
-                       if (r < ARCHIVE_WARN)
+                       if (r < ARCHIVE_WARN) {
+                               free(symname);
                                return (r);
-                       symname = realloc(symname, symsize + size + 1);
-                       if (symname == NULL) {
+                       }
+                       mem = realloc(symname, symsize + size + 1);
+                       if (mem == NULL) {
+                               free(symname);
                                archive_set_error(&a->archive, ENOMEM,
                                    "Can't allocate memory for Symname");
                                return (ARCHIVE_FATAL);
                        }
+                       symname = mem;
                        memcpy(symname+symsize, buff, size);
                        symsize += size;
                }
@@ -2563,7 +2568,7 @@ read_Times(struct archive_read *a, struct _7z_header_info *h, int type)
                if (parse_7zip_uint64(a, &(h->dataIndex)) < 0)
                        goto failed;
                if (1000000 < h->dataIndex)
-                       return (-1);
+                       goto failed;
        }
 
        for (i = 0; i < zip->numFiles; i++) {
index 92569bb64d34ec818b7d0414de834b2a1347a356..80197b3d778c730b1dfc0aaa645f9e18ff52d610 100644 (file)
@@ -3076,12 +3076,15 @@ xml2_xmlattr_setup(struct archive_read *a,
                attr->name = strdup(
                    (const char *)xmlTextReaderConstLocalName(reader));
                if (attr->name == NULL) {
+                       free(attr);
                        archive_set_error(&a->archive, ENOMEM, "Out of memory");
                        return (ARCHIVE_FATAL);
                }
                attr->value = strdup(
                    (const char *)xmlTextReaderConstValue(reader));
                if (attr->value == NULL) {
+                       free(attr->name);
+                       free(attr);
                        archive_set_error(&a->archive, ENOMEM, "Out of memory");
                        return (ARCHIVE_FATAL);
                }
index f4dbe306df62b1432f0c78f4f7f29bb495418835..f6334e4ab6b3a826bc58033b855499fa1a060e81 100644 (file)
@@ -1492,6 +1492,7 @@ file_new(struct archive_write *a, struct archive_entry *entry,
 
        if (0 > archive_entry_pathname_l(entry, &u16, &u16len, zip->sconv)) {
                if (errno == ENOMEM) {
+                       free(file);
                        archive_set_error(&a->archive, ENOMEM,
                            "Can't allocate memory for UTF-16LE");
                        return (ARCHIVE_FATAL);
@@ -1503,6 +1504,7 @@ file_new(struct archive_write *a, struct archive_entry *entry,
        }
        file->utf16name = malloc(u16len + 2);
        if (file->utf16name == NULL) {
+               free(file);
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate memory for Name");
                return (ARCHIVE_FATAL);
@@ -1914,6 +1916,7 @@ compression_init_encoder_lzma(struct archive *a,
        if (level > 6)
                level = 6;
        if (lzma_lzma_preset(&lzma_opt, level)) {
+               free(strm);
                lastrm->real_stream = NULL;
                archive_set_error(a, ENOMEM,
                    "Internal error initializing compression library");
index 988a971e0bd206db03bbe0c7517065c9c767c240..e60c99ce10061aadcf1add33a6da7dbc16608602 100644 (file)
@@ -2872,6 +2872,7 @@ compression_init_encoder_xz(struct archive *a,
        if (level > 6)
                level = 6;
        if (lzma_lzma_preset(&lzma_opt, level)) {
+               free(strm);
                lastrm->real_stream = NULL;
                archive_set_error(a, ENOMEM,
                    "Internal error initializing compression library");
index 3801ce1fa5ac026457b08c2f3aafbb261e1fca2e..e47464dc1a3b02cf2fff65945d0138567c34796e 100644 (file)
@@ -291,6 +291,7 @@ archive_write_set_format_zip(struct archive *_a)
        zip->len_buf = 65536;
        zip->buf = malloc(zip->len_buf);
        if (zip->buf == NULL) {
+               free(zip);
                archive_set_error(&a->archive, ENOMEM,
                    "Can't allocate compression buffer");
                return (ARCHIVE_FATAL);
@@ -411,6 +412,8 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
 
                if (archive_entry_pathname_l(entry, &p, &len, sconv) != 0) {
                        if (errno == ENOMEM) {
+                               archive_entry_free(l->entry);
+                               free(l);
                                archive_set_error(&a->archive, ENOMEM,
                                    "Can't allocate memory for Pathname");
                                return (ARCHIVE_FATAL);