]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix bugs that Clang Static Analyzer pointed out:
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 11 Sep 2012 11:09:30 +0000 (20:09 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 11 Sep 2012 11:09:30 +0000 (20:09 +0900)
 - Double free
 - Use-after-free

libarchive/archive_string.c

index 870cf37d5bfedcf1415a559cf465ea21e334fc95..d75966f3f4bf2c59cb6d8673beabc3fb4ecdc2b3 100644 (file)
@@ -306,6 +306,9 @@ archive_string_ensure(struct archive_string *as, size_t s)
        /* Now we can reallocate the buffer. */
        p = (char *)realloc(as->s, new_length);
        if (p == NULL) {
+               /* Prevent the duble free of as->s in archive_string_free
+                * since realloc function already freed the memory. */
+               as->s = NULL;
                /* On failure, wipe the string and return NULL. */
                archive_string_free(as);
                errno = ENOMEM;/* Make sure errno has ENOMEM. */
@@ -1120,8 +1123,8 @@ create_sconv_object(const char *fc, const char *tc,
        }
        sc->to_charset = strdup(tc);
        if (sc->to_charset == NULL) {
-               free(sc);
                free(sc->from_charset);
+               free(sc);
                return (NULL);
        }
        archive_string_init(&sc->utftmp);