]> granicus.if.org Git - graphviz/commitdiff
smyrna on_gvprbuttonsave_clicked: fix memory leak
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 10 Oct 2022 15:13:56 +0000 (08:13 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 15 Oct 2022 00:32:13 +0000 (17:32 -0700)
The `gtk_text_buffer_get_text` docs¹ note:

  Return value
  …
  The caller of the method takes ownership of the data, and is responsible for
  freeing it.

¹ https://docs.gtk.org/gtk4/method.TextBuffer.get_text.html

cmd/smyrna/gui/menucallbacks.c

index 4e4e8b6eff1301395cf91daf05a4873db262c979..772bb63d3478f1a3d59c08eafd099e8071c91404 100644 (file)
@@ -21,6 +21,7 @@
 #include <assert.h>
 #include <ctype.h>
 #include <glib.h>
+#include <stdlib.h>
 #include  "frmobjectui.h"
 
 void mAttributesSlot(GtkWidget * widget, gpointer user_data)
@@ -414,6 +415,7 @@ void on_gvprbuttonsave_clicked(GtkWidget * widget, gpointer user_data)
            gtk_text_buffer_get_end_iter(gtkbuf, &endit);
            bf2 = gtk_text_buffer_get_text(gtkbuf, &startit, &endit, 0);
            fprintf(output_file, "%s", bf2);
+           free(bf2);
            fclose(output_file);
        }