Fix memory leaks reported by Address Sanitizer.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 26 Dec 2020 00:22:14 +0000 (16:22 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 26 Dec 2020 06:04:43 +0000 (22:04 -0800)
src/libpspp/i18n.c
src/output/options.c
src/output/pivot-table.c
src/output/spv-driver.c
src/output/spv/spv-light-decoder.c

index fed6113503328e7e2c232947d45dc6d67081f92a..d553e135540c263e9eccf630073c96f31272b9ec 100644 (file)
@@ -641,7 +641,9 @@ void
 i18n_init (void)
 {
   setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, relocate(locale_dir));
+  char *allocated;
+  bindtextdomain (PACKAGE, relocate2 (locale_dir, &allocated));
+  free (allocated);
   textdomain (PACKAGE);
 
   assert (default_encoding == NULL);
index 8d15d1cc4a7162b57b034443c46eb44d266b4ab5..74bc751c5595bed2137ef3f6e110c91e5cf80850 100644 (file)
@@ -607,20 +607,15 @@ parse_color__ (const char *s, struct cell_color *color)
 struct cell_color
 parse_color (struct driver_option *o)
 {
+  struct cell_color color = CELL_COLOR_BLACK;
+  parse_color__ (o->default_value, &color);
   if (o->value)
     {
-      struct cell_color color;
-      if (parse_color__ (o->value, &color))
-        return color;
-
-      msg (MW, _("%s: `%s' is `%s', which could not be parsed as a color"),
-           o->driver_name, o->name, o->value);
+      if (!parse_color__ (o->value, &color))
+        msg (MW, _("%s: `%s' is `%s', which could not be parsed as a color"),
+             o->driver_name, o->name, o->value);
     }
-
-  struct cell_color color;
-  if (parse_color__ (o->default_value, &color))
-    return color;
-
-  return (struct cell_color) CELL_COLOR_BLACK;
+  driver_option_destroy (o);
+  return color;
 }
 
index 3d76ea2afa93ce79f88667380ce789641280757b..ad95d71fdb04d1c7f6d3950be6145cb374105a2b 100644 (file)
@@ -148,7 +148,10 @@ default_look (const struct pivot_table_look *new)
     {
       char *error = pivot_table_look_read ("default.stt", &look);
       if (error)
-        look = pivot_table_look_ref (pivot_table_look_builtin_default ());
+        {
+          free (error);
+          look = pivot_table_look_ref (pivot_table_look_builtin_default ());
+        }
     }
   return look;
 }
@@ -175,10 +178,11 @@ pivot_table_look_read (const char *name, struct pivot_table_look **lookp)
   size_t n = 0;
   path[n++] = ".";
   const char *home = getenv ("HOME");
+  char *allocated = NULL;
   if (home != NULL)
-    path[n++] = xasprintf ("%s/.pspp/looks", home);
-  char *allocated;
-  path[n++] = relocate2 (PKGDATADIR "/looks", &allocated);
+    path[n++] = allocated = xasprintf ("%s/.pspp/looks", home);
+  char *allocated2;
+  path[n++] = relocate2 (PKGDATADIR "/looks", &allocated2);
   path[n++] = NULL;
 
   /* Search path. */
@@ -190,6 +194,7 @@ pivot_table_look_read (const char *name, struct pivot_table_look **lookp)
       free (name2);
     }
   free (allocated);
+  free (allocated2);
   if (!file)
     return xasprintf ("%s: not found", name);
 
index fed7db75759c0affe80321f90ffcc74494eb9250..0c9d1412a5584514d4bf45be1139bf94ae4ce7ad 100644 (file)
@@ -108,8 +108,12 @@ spv_submit (struct output_driver *driver,
         spv_writer_put_table (spv->writer, table_item->pt);
     }
   else if (is_text_item (output_item))
-    spv_writer_put_text (spv->writer, to_text_item (output_item),
-                         output_get_command_name ());
+    {
+      char *command_id = output_get_command_name ();
+      spv_writer_put_text (spv->writer, to_text_item (output_item),
+                           command_id);
+      free (command_id);
+    }
   else if (is_page_eject_item (output_item))
     spv_writer_eject_page (spv->writer);
   else if (is_page_setup_item (output_item))
index 990a847b8527920487b006c972486e47031f3fb5..93ca8a29e43e759d86fce97ec61a1e88b4aab377 100644 (file)
@@ -467,6 +467,7 @@ decode_spvlb_area (const struct spvlb_area *in, struct table_area_style *out,
   if (error)
     return error;
 
+  table_area_style_uninit (out);
   *out = (struct table_area_style) {
     .font_style = {
       .bold = (in->style & 1) != 0,