]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix zstd memory allocation and null checks 905/head
authorSean Purcell <iburinoc@gmail.com>
Tue, 16 May 2017 14:00:51 +0000 (10:00 -0400)
committerSean Purcell <iburinoc@gmail.com>
Tue, 16 May 2017 14:00:51 +0000 (10:00 -0400)
libarchive/archive_read_support_filter_zstd.c

index f8a7590688a70b3f25d26515f0f5242f541d956a..c8bb36be703cee07f30ac3525898aaa6054624b8 100644 (file)
@@ -165,28 +165,29 @@ zstd_bidder_init(struct archive_read_filter *self)
        struct private_data *state;
        const size_t out_block_size = ZSTD_DStreamOutSize();
        void *out_block;
+       ZSTD_DStream *dstream;
 
        self->code = ARCHIVE_FILTER_ZSTD;
        self->name = "zstd";
 
        state = (struct private_data *)calloc(sizeof(*state), 1);
        out_block = (unsigned char *)malloc(out_block_size);
+       dstream = ZSTD_createDStream();
 
-       self->data = state;
-
-       state->dstream = ZSTD_createDStream();
-
-       if (state == NULL || out_block == NULL || state->dstream == NULL) {
+       if (state == NULL || out_block == NULL || dstream == NULL) {
                free(out_block);
                free(state);
-        ZSTD_freeDStream(state->dstream); /* supports free on NULL */
+               ZSTD_freeDStream(dstream); /* supports free on NULL */
                archive_set_error(&self->archive->archive, ENOMEM,
                    "Can't allocate data for zstd decompression");
                return (ARCHIVE_FATAL);
        }
 
+       self->data = state;
+
        state->out_block_size = out_block_size;
        state->out_block = out_block;
+       state->dstream = dstream;
        self->read = zstd_filter_read;
        self->skip = NULL; /* not supported */
        self->close = zstd_filter_close;