fix error-handing code in localealias.c
Bruno Haible
bruno@clisp.org
Fri Aug 19 11:58:00 GMT 2005
Hi,
The code in intl/localealias.c leaks a file descriptor and leaves the 'map'
array unsorted in case of memory allocation failure. Here is a probable
fix. (Untested.)
2005-08-19 Bruno Haible <bruno@clisp.org>
* intl/localealias.c (read_alias_file): In case of failure, close the
file descriptor and sort the array before returning.
diff -c -3 -r1.42 localealias.c
*** intl/localealias.c 4 Sep 2003 08:25:12 -0000 1.42
--- intl/localealias.c 19 Aug 2005 11:54:26 -0000
***************
*** 1,5 ****
/* Handle aliases for locale names.
! Copyright (C) 1995-2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
--- 1,5 ----
/* Handle aliases for locale names.
! Copyright (C) 1995-2002, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
***************
*** 295,301 ****
if (nmap >= maxmap)
if (__builtin_expect (extend_alias_table (), 0))
! return added;
alias_len = strlen (alias) + 1;
value_len = strlen (value) + 1;
--- 295,301 ----
if (nmap >= maxmap)
if (__builtin_expect (extend_alias_table (), 0))
! goto out;
alias_len = strlen (alias) + 1;
value_len = strlen (value) + 1;
***************
*** 308,314 ****
? alias_len + value_len : 1024));
char *new_pool = (char *) realloc (string_space, new_size);
if (new_pool == NULL)
! return added;
if (__builtin_expect (string_space != new_pool, 0))
{
--- 308,314 ----
? alias_len + value_len : 1024));
char *new_pool = (char *) realloc (string_space, new_size);
if (new_pool == NULL)
! goto out;
if (__builtin_expect (string_space != new_pool, 0))
{
***************
*** 349,354 ****
--- 349,355 ----
while (strchr (buf, '\n') == NULL);
}
+ out:
/* Should we test for ferror()? I think we have to silently ignore
errors. --drepper */
fclose (fp);
More information about the Libc-alpha
mailing list