From 66649313ae14ecd13d6bc51178678b7f6b1a648c Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Sun, 22 Mar 2015 22:02:16 +0800 Subject: [PATCH] Insure file descriptor is properly closed when doing filename completion. --- input.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/input.c b/input.c index ba8fd9b..2d54c6e 100644 --- a/input.c +++ b/input.c @@ -539,6 +539,11 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar) mlwrite(""); TTflush(); + if( tmpf != NULL) { + fclose( tmpf) ; + unlink( tmp) ; + } + /* if we default the buffer, return FALSE */ if (buf[0] == 0) return FALSE; @@ -553,6 +558,11 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar) /* Abort the input? */ ctrlg(FALSE, 0); TTflush(); + if( tmpf != NULL) { + fclose( tmpf) ; + unlink( tmp) ; + } + return ABORT; } else if ((c == 0x7F || c == 0x08) && quotef == FALSE) { /* rubout/erase */ @@ -628,8 +638,12 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar) if (nskip < 0) { buf[ocpos] = 0; #if UNIX - if (tmpf != NULL) + if (tmpf != NULL) { fclose(tmpf); + tmpf = NULL ; + unlink( tmp) ; + } + strcpy(tmp, "/tmp/meXXXXXX"); strcpy(ffbuf, "echo "); strcat(ffbuf, buf); @@ -712,7 +726,6 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar) TTflush(); #if UNIX rewind(tmpf); - unlink(tmp); #endif #endif