From 48cf3a22e06ee7a2eafc5dc405bbd6c5b84bcb31 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 20 Jan 2016 02:43:56 +0100 Subject: [PATCH] Error out earlier Signed-off-by: Sebastian Ramacher --- zathura/zathura.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/zathura/zathura.c b/zathura/zathura.c index 70c4cd2..7665814 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -542,6 +542,11 @@ prepare_document_open_from_stdin(const char* path) return NULL; } + if (infileno == -1) { + girara_error("Can not read from file descriptor."); + return NULL; + } + GError* error = NULL; gchar* file = NULL; gint handle = g_file_open_tmp("zathura.stdin.XXXXXX", &file, &error); @@ -554,14 +559,6 @@ prepare_document_open_from_stdin(const char* path) } // read and dump to temporary file - if (infileno == -1) { - girara_error("Can not read from file descriptor."); - close(handle); - g_unlink(file); - g_free(file); - return NULL; - } - char buffer[BUFSIZ]; ssize_t count = 0; while ((count = read(infileno, buffer, BUFSIZ)) > 0) {