fix directory descriptor leak [from michael at moria dot de]
This commit is contained in:
parent
401927b1d5
commit
98e93eb66e
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: readline.c,v 1.25 2002/10/27 21:43:35 christos Exp $ */
|
/* $NetBSD: readline.c,v 1.26 2003/01/21 17:41:38 christos Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#if !defined(lint) && !defined(SCCSID)
|
#if !defined(lint) && !defined(SCCSID)
|
||||||
__RCSID("$NetBSD: readline.c,v 1.25 2002/10/27 21:43:35 christos Exp $");
|
__RCSID("$NetBSD: readline.c,v 1.26 2003/01/21 17:41:38 christos Exp $");
|
||||||
#endif /* not lint && not SCCSID */
|
#endif /* not lint && not SCCSID */
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -1281,10 +1281,6 @@ filename_completion_function(const char *text, int state)
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (state == 0 || dir == NULL) {
|
if (state == 0 || dir == NULL) {
|
||||||
if (dir != NULL) {
|
|
||||||
closedir(dir);
|
|
||||||
dir = NULL;
|
|
||||||
}
|
|
||||||
temp = strrchr(text, '/');
|
temp = strrchr(text, '/');
|
||||||
if (temp) {
|
if (temp) {
|
||||||
char *nptr;
|
char *nptr;
|
||||||
|
@ -1332,6 +1328,10 @@ filename_completion_function(const char *text, int state)
|
||||||
if (filename_len == 0)
|
if (filename_len == 0)
|
||||||
return (NULL); /* no expansion possible */
|
return (NULL); /* no expansion possible */
|
||||||
|
|
||||||
|
if (dir != NULL) {
|
||||||
|
(void)closedir(dir);
|
||||||
|
dir = NULL;
|
||||||
|
}
|
||||||
dir = opendir(dirname ? dirname : ".");
|
dir = opendir(dirname ? dirname : ".");
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return (NULL); /* cannot open the directory */
|
return (NULL); /* cannot open the directory */
|
||||||
|
@ -1369,8 +1369,11 @@ filename_completion_function(const char *text, int state)
|
||||||
/* test, if it's directory */
|
/* test, if it's directory */
|
||||||
if (stat(temp, &stbuf) == 0 && S_ISDIR(stbuf.st_mode))
|
if (stat(temp, &stbuf) == 0 && S_ISDIR(stbuf.st_mode))
|
||||||
strcat(temp, "/"); /* safe */
|
strcat(temp, "/"); /* safe */
|
||||||
} else
|
} else {
|
||||||
|
(void)closedir(dir);
|
||||||
|
dir = NULL;
|
||||||
temp = NULL;
|
temp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return (temp);
|
return (temp);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue