From 7762bc98a2dfefab2ac4cf9e60e3ad3822ef9d6d Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 14 Apr 1998 16:03:09 +0000 Subject: [PATCH] (__open_catalog): Fix problems with reading non-files. Always close file. --- catgets/open_catalog.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/catgets/open_catalog.c b/catgets/open_catalog.c index 80d2899a36b..fa4f0778189 100644 --- a/catgets/open_catalog.c +++ b/catgets/open_catalog.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996 Free Software Foundation, Inc. +/* Copyright (C) 1996, 1998 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper, . @@ -35,7 +35,7 @@ void __open_catalog (__nl_catd catalog, int with_path) { - int fd; + int fd = -1; struct stat st; int swapping; @@ -161,8 +161,9 @@ __open_catalog (__nl_catd catalog, int with_path) } } - if (fd < 0 || __fstat (fd, &st) < 0) + if (fd < 0 || __fstat (fd, &st) < 0 || !S_ISREG (st.st_mode)) { + __close (fd); catalog->status = nonexisting; return; } @@ -194,6 +195,7 @@ __open_catalog (__nl_catd catalog, int with_path) catalog->file_ptr = malloc (st.st_size); if (catalog->file_ptr == NULL) { + __close (fd); catalog->status = nonexisting; return; } @@ -205,6 +207,7 @@ __open_catalog (__nl_catd catalog, int with_path) + (st.st_size - todo)), todo); if (now == 0) { + __close (fd); free ((void *) catalog->file_ptr); catalog->status = nonexisting; return; -- 2.47.2