Free stylesheets properly
authorThomas White <taw@bitwiz.me.uk>
Thu, 2 May 2019 19:28:38 +0000 (21:28 +0200)
committerThomas White <taw@bitwiz.me.uk>
Thu, 2 May 2019 19:28:38 +0000 (21:28 +0200)
libstorycode/narrative.c
libstorycode/stylesheet.c

index 7e58f88..7256651 100644 (file)
@@ -84,6 +84,7 @@ static void narrative_item_destroy(struct narrative_item *item)
 }
 
 
+/* Free the narrative and all contents, but not the stylesheet */
 void narrative_free(Narrative *n)
 {
        int i;
index c4625f2..2b549db 100644 (file)
@@ -133,8 +133,20 @@ static void default_style(struct style *s)
 }
 
 
+static void free_style_contents(struct style *sty)
+{
+       int i;
+       for ( i=0; i<sty->n_substyles; i++ ) {
+               free_style_contents(&sty->substyles[i]);
+       }
+       free(sty->name);
+       free(sty->substyles);
+}
+
+
 void stylesheet_free(Stylesheet *s)
 {
+       free_style_contents(&s->top);
        free(s);
 }