summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2020-08-24 15:52:34 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2020-08-24 17:44:07 +0100
commit67ce7b204483894fffb7ea6feddcbac00bc1a9bf (patch)
treeaf4c1ce55f42f5e047e85adabff50cec66eab590
parentcfda3a24d0cb5fd54049705cbdfae78fa4ceff10 (diff)
downloadjson-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.c17
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);