From: Matthew Fernandez Date: Sat, 30 May 2020 02:01:39 +0000 (-0700) Subject: duplicate backing memory for plugin typestr X-Git-Tag: 2.44.1~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1bf25fefc5a7d0c7534e58ea405494f645321065;p=graphviz duplicate backing memory for plugin typestr Following this change, plugins no longer retain a typestr pointer that was malloced elsewhere. This lets the memory for plugins be manged more orthogonally to other concerns. Related to #1543. --- diff --git a/lib/gvc/gvcint.h b/lib/gvc/gvcint.h index 7b2a1f119..0f8c21aeb 100644 --- a/lib/gvc/gvcint.h +++ b/lib/gvc/gvcint.h @@ -49,7 +49,7 @@ extern "C" { struct gvplugin_available_s { gvplugin_available_t *next; /* next plugin in linked list, or NULL */ - const char *typestr; /* type string, e.g. "png" or "ps" */ + char *typestr; /* type string, e.g. "png" or "ps" */ int quality; /* Programmer assigned quality ranking within type (+ve or -ve int). First implementation of type should be given "0" quality */ gvplugin_package_t *package; /* details of library containing plugin */ diff --git a/lib/gvc/gvcontext.c b/lib/gvc/gvcontext.c index 73ca5a71c..c29d8e2ef 100644 --- a/lib/gvc/gvcontext.c +++ b/lib/gvc/gvcontext.c @@ -103,6 +103,7 @@ int gvFreeContext(GVC_t * gvc) for (i = 0; i != num_apis; ++i) { for (api = gvc->apis[i]; api != NULL; api = api_next) { api_next = api->next; + free(api->typestr); free(api); } } diff --git a/lib/gvc/gvplugin.c b/lib/gvc/gvplugin.c index 99b98b1b2..d10222f17 100644 --- a/lib/gvc/gvplugin.c +++ b/lib/gvc/gvplugin.c @@ -85,7 +85,12 @@ boolean gvplugin_install(GVC_t * gvc, api_t api, const char *typestr, { gvplugin_available_t *plugin, **pnext; #define TYPSIZ 63 - char *p, pins[TYPSIZ + 1], pnxt[TYPSIZ + 1]; + char *p, *t, pins[TYPSIZ + 1], pnxt[TYPSIZ + 1]; + + /* duplicate typestr to later save in the plugin list */ + t = strdup(typestr); + if (t == NULL) + return FALSE; strncpy(pins, typestr, TYPSIZ); if ((p = strchr(pins, ':'))) @@ -119,7 +124,7 @@ boolean gvplugin_install(GVC_t * gvc, api_t api, const char *typestr, plugin = GNEW(gvplugin_available_t); plugin->next = *pnext; *pnext = plugin; - plugin->typestr = typestr; + plugin->typestr = t; plugin->quality = quality; plugin->package = package; plugin->typeptr = typeptr; /* null if not loaded */