summaryrefslogtreecommitdiffstats
path: root/lib/realloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/realloc.c')
-rw-r--r--lib/realloc.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/realloc.c b/lib/realloc.c
index ccbf991..fe94822 100644
--- a/lib/realloc.c
+++ b/lib/realloc.c
@@ -1,5 +1,5 @@
1/* Work around bug on some systems where realloc (NULL, 0) fails. 1/* realloc() function that is glibc compatible.
2 Copyright (C) 1997, 2003 Free Software Foundation, Inc. 2 Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -13,11 +13,11 @@
13 13
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation, 15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17 17
18/* written by Jim Meyering */ 18/* written by Jim Meyering */
19 19
20#if HAVE_CONFIG_H 20#ifdef HAVE_CONFIG_H
21# include <config.h> 21# include <config.h>
22#endif 22#endif
23#undef realloc 23#undef realloc
@@ -32,8 +32,15 @@ void *
32rpl_realloc (void *p, size_t n) 32rpl_realloc (void *p, size_t n)
33{ 33{
34 if (n == 0) 34 if (n == 0)
35 n = 1; 35 {
36 if (p == 0) 36 n = 1;
37
38 /* In theory realloc might fail, so don't rely on it to free. */
39 free (p);
40 p = NULL;
41 }
42
43 if (p == NULL)
37 return malloc (n); 44 return malloc (n);
38 return realloc (p, n); 45 return realloc (p, n);
39} 46}