From 35cf05a2036e9c3562d275ed812059dd7b2b5d01 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 25 Dec 2020 16:22:14 -0800 Subject: [PATCH] Fix memory leaks reported by Address Sanitizer. --- src/libpspp/i18n.c | 4 +++- src/output/options.c | 19 +++++++------------ src/output/pivot-table.c | 13 +++++++++---- src/output/spv-driver.c | 8 ++++++-- src/output/spv/spv-light-decoder.c | 1 + 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/libpspp/i18n.c b/src/libpspp/i18n.c index fed6113503..d553e13554 100644 --- a/src/libpspp/i18n.c +++ b/src/libpspp/i18n.c @@ -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); diff --git a/src/output/options.c b/src/output/options.c index 8d15d1cc4a..74bc751c55 100644 --- a/src/output/options.c +++ b/src/output/options.c @@ -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; } diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index 3d76ea2afa..ad95d71fdb 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -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); diff --git a/src/output/spv-driver.c b/src/output/spv-driver.c index fed7db7575..0c9d1412a5 100644 --- a/src/output/spv-driver.c +++ b/src/output/spv-driver.c @@ -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)) diff --git a/src/output/spv/spv-light-decoder.c b/src/output/spv/spv-light-decoder.c index 990a847b85..93ca8a29e4 100644 --- a/src/output/spv/spv-light-decoder.c +++ b/src/output/spv/spv-light-decoder.c @@ -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, -- 2.30.2