From 3210e5be2831245bb485db05c78a5cdc93be4fb7 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Mon, 4 Oct 2010 10:08:21 +0200 Subject: [PATCH] some error handling and close handle before deleting the temporary file --- zathura.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/zathura.c b/zathura.c index 9254145..e2cfd85 100644 --- a/zathura.c +++ b/zathura.c @@ -1419,9 +1419,21 @@ open_stdin(gchar* password) } // read from stdin and dump to temporary file + int stdinfno = fileno(stdin); + if (stdinfno == -1) + { + gchar* message = g_strdup_printf("Can not read from stdin."); + notify(ERROR, message); + g_free(message); + close(handle); + g_unlink(file); + g_free(file); + return FALSE; + + } + char buffer[BUFSIZ]; ssize_t count = 0; - int stdinfno = fileno(stdin); while ((count = read(stdinfno, buffer, BUFSIZ)) > 0) { if (write(handle, buffer, count) != count) @@ -1429,21 +1441,21 @@ open_stdin(gchar* password) gchar* message = g_strdup_printf("Can not write to temporary file: %s", file); notify(ERROR, message); g_free(message); + close(handle); g_unlink(file); g_free(file); - close(handle); return FALSE; } } if (count != 0) { - gchar* message = g_strdup_printf("Can not read from stdin"); + gchar* message = g_strdup_printf("Can not read from stdin."); notify(ERROR, message); g_free(message); + close(handle); g_unlink(file); g_free(file); - close(handle); return FALSE; }