diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2020-08-24 15:52:34 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2020-08-24 17:44:07 +0100 |
commit | 67ce7b204483894fffb7ea6feddcbac00bc1a9bf (patch) | |
tree | af4c1ce55f42f5e047e85adabff50cec66eab590 | |
parent | cfda3a24d0cb5fd54049705cbdfae78fa4ceff10 (diff) | |
download | json-glib-67ce7b204483894fffb7ea6feddcbac00bc1a9bf.tar.gz |
Plug leaks in json-glib-format
We're leaking a bunch of strings in error paths, as well as the stream
for the input file.
-rw-r--r-- | json-glib/json-glib-format.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/json-glib/json-glib-format.c b/json-glib/json-glib-format.c index 481b4d3..7a3ca26 100644 --- a/json-glib/json-glib-format.c +++ b/json-glib/json-glib-format.c @@ -93,12 +93,15 @@ format (JsonParser *parser, parse_res = json_parser_load_from_stream (parser, in, NULL, &error); if (!parse_res) { + char *uri = g_file_get_uri (file); + /* Translators: the first %s is the program name, the second one * is the URI of the file, the third is the error message. */ g_printerr (_("%s: %s: error parsing file: %s\n"), - g_get_prgname (), g_file_get_uri (file), error->message); + g_get_prgname (), uri, error->message); g_clear_error (&error); + g_free (uri); res = FALSE; goto out; } @@ -132,10 +135,13 @@ format (JsonParser *parser, if (written == -1 && errno != EINTR) { + char *uri = g_file_get_uri (file); + /* Translators: the first %s is the program name, the * second one is the URI of the file. */ - g_printerr (_("%s: %s: error writing to stdout"), g_get_prgname (), g_file_get_uri (file)); + g_printerr (_("%s: %s: error writing to stdout"), g_get_prgname (), uri); + g_free (uri); res = FALSE; goto out; } @@ -153,15 +159,20 @@ out: close_res = g_input_stream_close (in, NULL, &error); if (!close_res) { + char *uri = g_file_get_uri (file); + /* Translators: the first %s is the program name, the second one * is the URI of the file, the third is the error message. */ g_printerr (_("%s: %s: error closing: %s\n"), - g_get_prgname (), g_file_get_uri (file), error->message); + g_get_prgname (), uri, error->message); g_clear_error (&error); + g_free (uri); res = FALSE; } + g_object_unref (in); + if (fd != STDOUT_FILENO) g_close (fd, NULL); |