CodeQL MemoryMayNotBeFreed.ql grTCairo1.c GrTCairoPlotSVG()

created use of 'alloc' local variable to track when an allocation occurred
so exit path logic is more straight forward for compiler/analyser to see
potential optimisations.

the previous version was probably working just fine
This commit is contained in:
Darryl L. Miles 2025-02-13 08:22:28 +00:00 committed by Tim Edwards
parent e565b4c360
commit a764fdbbd1
1 changed files with 3 additions and 2 deletions

View File

@ -356,6 +356,7 @@ GrTCairoPlotSVG (char *filename, MagWindow *mw)
{
int screenw, screenh;
char *fileptr;
char *alloc = NULL;
cairo_surface_t *wind_surface;
cairo_t *wind_context;
@ -373,7 +374,7 @@ GrTCairoPlotSVG (char *filename, MagWindow *mw)
fileptr = filename;
if (strchr(filename, '.') == NULL)
{
fileptr = mallocMagic(strlen(filename) + 5);
fileptr = alloc = mallocMagic(strlen(filename) + 5);
sprintf(fileptr, "%s.svg", filename);
}
@ -387,7 +388,7 @@ GrTCairoPlotSVG (char *filename, MagWindow *mw)
cairo_svg_surface_restrict_to_version(tcairodata->surface,
CAIRO_SVG_VERSION_1_2);
if (fileptr != filename) freeMagic(fileptr);
if (alloc) freeMagic(alloc);
tcairodata->context = cairo_create(tcairodata->surface);
WindRedisplay(mw);