summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2004-04-19 18:59:52 +0000
committerJim Meyering <jim@meyering.net>2004-04-19 18:59:52 +0000
commitcb5f6b9ad36cc18020d5fec9d533101a1b370592 (patch)
treeecca98556b43ab8efe88715f45b28e87c568477c
parent332853e7227e963f4938275fcaf5acb43db91e23 (diff)
downloadcoreutils-cb5f6b9ad36cc18020d5fec9d533101a1b370592.tar.xz
(read_utmp) [UTMP_NAME_FUNCTION]: Upon realloc failure,
don't leak memory and do call END_UTMP_ENT.
-rw-r--r--lib/readutmp.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/readutmp.c b/lib/readutmp.c
index 71a913df0..896e976dc 100644
--- a/lib/readutmp.c
+++ b/lib/readutmp.c
@@ -1,5 +1,5 @@
/* GNU's read utmp module.
- Copyright (C) 1992-2001, 2003 Free Software Foundation, Inc.
+ Copyright (C) 1992-2001, 2003, 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -74,10 +74,16 @@ read_utmp (const char *filename, int *n_entries, STRUCT_UTMP **utmp_buf)
n_read = 0;
while ((u = GET_UTMP_ENT ()) != NULL)
{
+ STRUCT_UTMP *p;
++n_read;
- utmp = (STRUCT_UTMP *) realloc (utmp, n_read * sizeof (STRUCT_UTMP));
- if (utmp == NULL)
- return 1;
+ p = (STRUCT_UTMP *) realloc (utmp, n_read * sizeof (STRUCT_UTMP));
+ if (p == NULL)
+ {
+ free (utmp);
+ END_UTMP_ENT ();
+ return 1;
+ }
+ utmp = p;
utmp[n_read - 1] = *u;
}