shithub: jbig2

Download patch

ref: c241cf3a3b2b982577ed97aab47ea562e927bbea
parent: 36f5262823d30ea6d95b98d88f638d726be05114
author: Sebastian Rasmussen <sebras@gmail.com>
date: Sat Feb 9 08:34:38 EST 2019

jbig2dec: Return allocator once it is retired.

--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+Version 0.16
+
+* API change allowing for library users to get the custom allocator
+  so it may be freed if necessary. This is useful if the allocator
+  is extended with e.g. a custom pointer needed by the allocator
+  callbacks.
+
 Version 0.15 (2018 September 04)
 
 * Bug fix release, with many security related and stability fixes
--- a/jbig2.c
+++ b/jbig2.c
@@ -391,7 +391,7 @@
     }
 }
 
-void
+Jbig2Allocator *
 jbig2_ctx_free(Jbig2Ctx *ctx)
 {
     Jbig2Allocator *ca;
@@ -398,7 +398,7 @@
     int i;
 
     if (ctx == NULL)
-        return;
+        return NULL;
 
     ca = ctx->allocator;
     jbig2_free(ca, ctx->buf);
@@ -416,6 +416,8 @@
     }
 
     jbig2_free(ca, ctx);
+
+    return ca;
 }
 
 Jbig2GlobalCtx *
@@ -424,10 +426,10 @@
     return (Jbig2GlobalCtx *) ctx;
 }
 
-void
+Jbig2Allocator *
 jbig2_global_ctx_free(Jbig2GlobalCtx *global_ctx)
 {
-    jbig2_ctx_free((Jbig2Ctx *) global_ctx);
+    return jbig2_ctx_free((Jbig2Ctx *) global_ctx);
 }
 
 /* I'm not committed to keeping the word stream interface. It's handy
--- a/jbig2.h
+++ b/jbig2.h
@@ -79,11 +79,11 @@
 /* decoder context */
 Jbig2Ctx *jbig2_ctx_new(Jbig2Allocator *allocator,
                         Jbig2Options options, Jbig2GlobalCtx *global_ctx, Jbig2ErrorCallback error_callback, void *error_callback_data);
-void jbig2_ctx_free(Jbig2Ctx *ctx);
+Jbig2Allocator *jbig2_ctx_free(Jbig2Ctx *ctx);
 
 /* global context for embedded streams */
 Jbig2GlobalCtx *jbig2_make_global_ctx(Jbig2Ctx *ctx);
-void jbig2_global_ctx_free(Jbig2GlobalCtx *global_ctx);
+Jbig2Allocator *jbig2_global_ctx_free(Jbig2GlobalCtx *global_ctx);
 
 /* submit data to the decoder */
 int jbig2_data_in(Jbig2Ctx *ctx, const unsigned char *data, size_t size);