]> granicus.if.org Git - xz/commitdiff
liblzma: Handle allocation failures correctly in lzma_index_init().
authorLasse Collin <lasse.collin@tukaani.org>
Fri, 27 May 2011 19:09:49 +0000 (22:09 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 27 May 2011 19:09:49 +0000 (22:09 +0300)
Thanks to Jim Meyering.

src/liblzma/common/index.c

index ddb9d364362395da59923c9fbed696638e1459eb..9af4bc19d1b540c17f10af264dc365410b3b8c45 100644 (file)
@@ -398,10 +398,13 @@ extern LZMA_API(lzma_index *)
 lzma_index_init(lzma_allocator *allocator)
 {
        lzma_index *i = index_init_plain(allocator);
+       if (i == NULL)
+               return NULL;
+
        index_stream *s = index_stream_init(0, 0, 1, 0, allocator);
-       if (i == NULL || s == NULL) {
-               index_stream_end(s, allocator);
+       if (s == NULL) {
                lzma_free(i, allocator);
+               return NULL;
        }
 
        index_tree_append(&i->streams, &s->node);