# HG changeset patch # User Matti Hamalainen # Date 1583772954 -7200 # Node ID 0fc5ddaccc5775344fc6473e09cb164d071c58d0 # Parent a622d21833e1eae83d8b44e17640423503d13dcd Implement fclose() in mem ioctx, with an context flag for freeing the memory on fclose(). diff -r a622d21833e1 -r 0fc5ddaccc57 th_ioctx.h --- a/th_ioctx.h Mon Mar 09 18:54:37 2020 +0200 +++ b/th_ioctx.h Mon Mar 09 18:55:54 2020 +0200 @@ -49,6 +49,7 @@ size_t minAlloc; ///< Minimum allocation increase (0 = default) off_t memOffset; ///< Current offset in data uint8_t *memData; ///< Pointer to data + BOOL memFree; ///< TRUE = free the allocated memory on thfclose(), FALSE = no BOOL memWrite; ///< TRUE = memory can be written to / expanded etc. FALSE = no // Message functions diff -r a622d21833e1 -r 0fc5ddaccc57 th_ioctx_mem.c --- a/th_ioctx_mem.c Mon Mar 09 18:54:37 2020 +0200 +++ b/th_ioctx_mem.c Mon Mar 09 18:55:54 2020 +0200 @@ -43,6 +43,13 @@ } +static void th_mem_fclose(th_ioctx *ctx) +{ + if (ctx->memFree) + th_free_r(&ctx->memData); +} + + static BOOL th_mem_realloc(th_ioctx *ctx, const size_t newSize) { size_t grow; @@ -222,7 +229,7 @@ "MemIO", th_mem_fopen, - NULL, + th_mem_fclose, th_mem_freset, th_mem_ferror,