From 964056fb65575a1840dc542ed64accef842d8d85 Mon Sep 17 00:00:00 2001 From: "Andrew V. Samoilov" Date: Fri, 16 Jan 2015 21:35:30 +0200 Subject: [PATCH] * background.c (background_attention): Fix memory leak. --- src/background.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/background.c b/src/background.c index 4c79a77c7..563d8a7fb 100644 --- a/src/background.c +++ b/src/background.c @@ -170,6 +170,17 @@ destroy_task_and_return_fd (pid_t pid) * specified routine */ +static int +reading_failed (int i, char **data) +{ + while (i >= 0) + g_free (data[i--]); + message (D_ERROR, _("Background protocol error"), "%s", _("Reading failed")); + return 0; +} + +/* --------------------------------------------------------------------------------------------- */ + static int background_attention (int fd, void *closure) { @@ -234,8 +245,7 @@ background_attention (int fd, void *closure) (read (fd, &type, sizeof (type)) != sizeof (type)) || (read (fd, &have_ctx, sizeof (have_ctx)) != sizeof (have_ctx))) { - message (D_ERROR, _("Background protocol error"), _("Reading failed")); - return 0; + return reading_failed (-1, data); } if (argc > MAXCALLARGS) @@ -249,8 +259,7 @@ background_attention (int fd, void *closure) { if (read (fd, ctx, sizeof (file_op_context_t)) != sizeof (file_op_context_t)) { - message (D_ERROR, _("Background protocol error"), _("Reading failed")); - return 0; + return reading_failed (-1, data); } } @@ -260,14 +269,12 @@ background_attention (int fd, void *closure) if (read (fd, &size, sizeof (size)) != sizeof (size)) { - message (D_ERROR, _("Background protocol error"), _("Reading failed")); - return 0; + return reading_failed (i - 1, data); } data[i] = g_malloc (size + 1); if (read (fd, data[i], size) != size) { - message (D_ERROR, _("Background protocol error"), _("Reading failed")); - return 0; + return reading_failed (i, data); } data[i][size] = 0; /* NULL terminate the blocks (they could be strings) */ }