]> 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 09:52:30 +0000 (18:52 +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 0fef3c7458c7d521252673ff545f9a724d77d2ee..a43c0adf9c2abeab1e1c5770bad40737d12462ef 100644 (file)
@@ -749,6 +749,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 1e02467f47f8d0098d65302dfec00b975aafcad2..89eb573a6ed14b2807744f07ad63213c7ff4e919 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;
                }
@@ -2585,7 +2590,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 3565c22e6d0a9a2dde0fb93aa56c4e044b3be459..733011c262fe1dde945c9a63aec95fb7df304d14 100644 (file)
@@ -3078,12 +3078,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 251e8ee660b22dcc8867d44d4c9d86afec11e897..7e1240a2c32cfe421908d2c6e660ffdc2c4d3bb4 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 17f5ba635a64f829466fa1b3ffcf6d0b7fbdc06e..3a48e052fb71e0f835edd25c7daabb11beacf6d7 100644 (file)
@@ -2868,6 +2868,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 45492377a0f0a828f75b43ec9a702e202c40f41e..845c46ce8e7675e8290d89b7196cfa0bd853a910 100644 (file)
@@ -286,6 +286,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);
@@ -406,6 +407,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);
@@ -428,6 +431,8 @@ archive_write_zip_header(struct archive_write *a, struct archive_entry *entry)
                if (type == AE_IFLNK) {
                        if (archive_entry_symlink_l(entry, &p, &len, sconv)) {
                                if (errno == ENOMEM) {
+                                       archive_entry_free(l->entry);
+                                       free(l);
                                        archive_set_error(&a->archive, ENOMEM,
                                            "Can't allocate memory "
                                            " for Symlink");