brotli: Add cleanup after decompression is complete 09/285809/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Mon, 19 Dec 2022 15:53:00 +0000 (16:53 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 22 Dec 2022 15:02:51 +0000 (16:02 +0100)
Change-Id: Ice1f953ae36e7b9abfffe8d674379748a946be41

src/upgrade-apply/main.c
src/upgrade-apply/patch/brotli.c
src/upgrade-apply/patch/brotli.h
src/upgrade-apply/patch/patch.c
src/upgrade-apply/patch/patch_helper.c

index 51e17617c8bc19a6f1ca6a16f48c499a7e015e78..879952093f1abae4309938f0d684fc30c1b2bd40 100644 (file)
@@ -479,7 +479,7 @@ int main(int argc, char **argv)
 
                case KIND_BROTLI_PATCH:
                        {
-                               struct dec_funcs funcs = { init_brotli, decompress_brotli };
+                               struct dec_funcs funcs = { init_brotli, decompress_brotli, free_brotli };
                                r = apply_patch(parsed.patch_orig, parsed.dest, tar, parsed.dest_size, &funcs);
                                break;
                        }
index b5259bb13e105148c6a16be19020febe559c5b46..0627c5df2064841f264b35a5b742bfb13ba48779 100644 (file)
@@ -47,3 +47,10 @@ int decompress_brotli(struct bs_data *data)
     }
     return PF_OK;
 }
+
+void free_brotli(struct bs_data *data)
+{
+    assert(data);
+    BrotliDecoderState *bstate = (BrotliDecoderState*)data->state;
+    BrotliDecoderDestroyInstance(bstate);
+}
index 919caac2bf98b63e2dc12dc4de38e431e11647f0..612818a4fe7d22ed6995976ea3aeb4f54783d42a 100644 (file)
@@ -20,3 +20,4 @@
 
 int init_brotli(struct bs_data *data);
 int decompress_brotli(struct bs_data *data);
+void free_brotli(struct bs_data *data);
index be5f92fac0a92607e65efa127530d7a6d54ea28a..43f609dbf801faf61e2d0f0e9a2551c0a91fb038 100644 (file)
@@ -321,7 +321,7 @@ int read_header(struct dec_funcs *funcs, struct bs_data *data, uint8_t **buff_ou
             return PF_ERROR_OPEN_FILE;
         }
     } else if (target_size != data->dest.len) {
-        fprintf(stderr, "Declared target size differs from that read from the patch\n");
+        fprintf(stderr, "Declared target size differs from that read from the patch (%ld [patch] != %ld [declared])\n", target_size, data->dest.len);
         return PF_ERROR_INVALID_PATCH_FILE;
     }
 
index c85c9e6f1b58e14fb1cfd30c95817daa6ccd7883..be2d46f8c64e6353828ce8095d02b5f904c2ff5a 100644 (file)
@@ -20,6 +20,6 @@
 
 int apply_patch_brotli(const char *source_file, const char *dest_file, TAR *patch_tar, size_t dest_size)
 {
-    struct dec_funcs funcs = { init_brotli, decompress_brotli };
+    struct dec_funcs funcs = { init_brotli, decompress_brotli, free_brotli };
     return apply_patch(source_file, dest_file, patch_tar, dest_size, &funcs);
 }