From 54d37d681ce0d5f092859df0e48a0760e96eef13 Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Sat, 18 Mar 2017 16:57:24 -0400 Subject: [PATCH] FIXED: Free memory from asset hash --- Sources/libMultiMarkdown/mmd.c | 8 ++++++++ Sources/libMultiMarkdown/writer.c | 11 +++++++++++ Sources/libMultiMarkdown/writer.h | 1 + 3 files changed, 20 insertions(+) diff --git a/Sources/libMultiMarkdown/mmd.c b/Sources/libMultiMarkdown/mmd.c index a4b206c..5b06583 100644 --- a/Sources/libMultiMarkdown/mmd.c +++ b/Sources/libMultiMarkdown/mmd.c @@ -272,6 +272,14 @@ void mmd_engine_free(mmd_engine * e, bool freeDString) { } stack_free(e->metadata_stack); + + // Free asset hash + asset * a, * a_tmp; + HASH_ITER(hh, e->asset_hash, a, a_tmp) { + HASH_DEL(e->asset_hash, a); // Remove item from hash + asset_free(a); // Free the asset + } + free(e); } diff --git a/Sources/libMultiMarkdown/writer.c b/Sources/libMultiMarkdown/writer.c index 752de3c..45c03f4 100644 --- a/Sources/libMultiMarkdown/writer.c +++ b/Sources/libMultiMarkdown/writer.c @@ -2321,6 +2321,16 @@ asset * asset_new(char * url, scratch_pad * scratch) { } +void asset_free(asset * a) { + if (a) { + free(a->url); + free(a->asset_path); + } + + free(a); +} + + asset * extract_asset(scratch_pad * scratch, char * url) { asset * a; @@ -2329,6 +2339,7 @@ asset * extract_asset(scratch_pad * scratch, char * url) { return a; } + void store_asset(scratch_pad * scratch, char * url) { asset * a = extract_asset(scratch, url); diff --git a/Sources/libMultiMarkdown/writer.h b/Sources/libMultiMarkdown/writer.h index 2ac2681..08ed9f3 100644 --- a/Sources/libMultiMarkdown/writer.h +++ b/Sources/libMultiMarkdown/writer.h @@ -245,6 +245,7 @@ short raw_level_for_header(token * header); void store_asset(scratch_pad * scratch_pad, char * url); asset * extract_asset(scratch_pad * scratch, char * url); +void asset_free(asset * a); #endif -- 2.40.0