From: Michael Orlitzky Date: Sun, 6 Aug 2023 06:05:38 +0000 (-0400) Subject: io-svg.c: simplify memory management for context->svg_data X-Git-Tag: 0.0.1~22 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=96deefceb53d73852b56ca0c71c08ba9abc758ca;p=libsvgtiny-pixbuf.git io-svg.c: simplify memory management for context->svg_data Match up the malloc/free for this buffer rather than freeing it as soon as possible in some helper function three levels down. --- diff --git a/io-svg.c b/io-svg.c index 8bea9ef..543162f 100644 --- a/io-svg.c +++ b/io-svg.c @@ -131,7 +131,6 @@ static diagram_t* svgtiny_diagram_from_buffer(char* buffer, } code = svgtiny_parse(diagram, buffer, bytecount, "", width, height); - free(buffer); if (code != svgtiny_OK) { switch (code) { @@ -340,8 +339,7 @@ static gpointer gdk_pixbuf_begin_load(GdkPixbufModuleSizeFunc size_func, context->updated_func = updated_func; context->user_data = user_data; - /* YOLO, no error checking */ - context->svg_data = g_malloc(0); + context->svg_data = NULL; context->svg_data_size = 0; return context; @@ -400,6 +398,7 @@ static gboolean gdk_pixbuf_stop_load(gpointer data, GError **error) { g_propagate_error(error, sub_error); result = FALSE; } + g_free(context->svg_data); g_free(context); return result;