From 026b0625a68e716c77b4f90009013d2f72cee377 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Mon, 6 Feb 2017 11:41:19 +0100 Subject: [PATCH] kresc: fix coverity warning 155938 The FD leak happened only when we exit the process, but still... --- daemon/kresc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/daemon/kresc.c b/daemon/kresc.c index ecac2d1a0..72a6d1729 100644 --- a/daemon/kresc.c +++ b/daemon/kresc.c @@ -28,6 +28,7 @@ #include #include #include +#include #define HISTORY_FILE "kresc_history" #define PROGRAM_NAME "kresc" @@ -275,23 +276,28 @@ static int init_tty(const char *path) size_t plen = strlen(path); if (plen + 1 > sizeof(addr.sun_path)) { fprintf(stderr, "Path too long\n"); + close(fd); return 1; } memcpy(addr.sun_path, path, plen + 1); if (connect(fd, (const struct sockaddr *)&addr, sizeof(addr))) { perror("While connecting to daemon"); + close(fd); return 1; } g_tty = fdopen(fd, "r+"); if (!g_tty) { perror("While opening TTY"); + close(fd); return 1; } // Switch to binary mode and consume the text "> ". if (fprintf(g_tty, "__binary\n") < 0 || !fread(&addr, 2, 1, g_tty) || fflush(g_tty)) { perror("While initializing TTY"); + fclose(g_tty); + g_tty = NULL; return 1; } -- 2.47.3