From: Vladimír Čunát Date: Mon, 6 Feb 2017 10:41:19 +0000 (+0100) Subject: kresc: fix coverity warning 155938 X-Git-Tag: v1.3.0~23^2~84^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=026b0625a68e716c77b4f90009013d2f72cee377;p=thirdparty%2Fknot-resolver.git kresc: fix coverity warning 155938 The FD leak happened only when we exit the process, but still... --- 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; }