chiark / gitweb /
Fix a handful of memory leaks in the midend.
authorSimon Tatham <anakin@pobox.com>
Fri, 5 Apr 2019 18:29:23 +0000 (19:29 +0100)
committerSimon Tatham <anakin@pobox.com>
Fri, 5 Apr 2019 18:29:23 +0000 (19:29 +0100)
I happened to notice these when running dominosa --generate under Leak
Sanitiser.

midend.c

index 5f3abcf9409fe970fcb1721f668d0aab90a9d9b4..b3032e7287aa37fc75ee3c0af2e2a3f2a53b3f6f 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -171,6 +171,8 @@ midend *midend_new(frontend *fe, const game *ourgame,
     me->params = ourgame->default_params();
     me->game_id_change_notify_function = NULL;
     me->game_id_change_notify_ctx = NULL;
+    me->encoded_presets = NULL;
+    me->n_encoded_presets = 0;
 
     /*
      * Allow environment-based changing of the default settings by
@@ -261,8 +263,13 @@ static void midend_free_preset_menu(midend *me, struct preset_menu *menu)
 
 void midend_free(midend *me)
 {
+    int i;
+
     midend_free_game(me);
 
+    for (i = 0; i < me->n_encoded_presets; i++)
+        sfree(me->encoded_presets[i]);
+    sfree(me->encoded_presets);
     if (me->drawing)
        drawing_free(me->drawing);
     random_free(me->random);