bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gnulib] FYI: fix minor problems with readutmp


From: Jim Meyering
Subject: [Bug-gnulib] FYI: fix minor problems with readutmp
Date: Mon, 19 Apr 2004 22:15:58 +0200

I don't think any package other than coreutils uses the
readutmp module, but just in case, here's a heads-up.
The read_utmp function could leak memory upon failure,
and maybe even a file descriptor, depending on the
definition of END_UTMP_ENT.

2004-04-18  Jim Meyering  <address@hidden>

        * readutmp.c (read_utmp) [UTMP_NAME_FUNCTION]: Upon realloc failure,
        don't leak memory and do call END_UTMP_ENT.

2004-04-19  Jim Meyering  <address@hidden>

        * readutmp.m4 (gl_PREREQ_READUTMP): Require gl_FUNC_FREE,
        now that readutmp.c may call `free (0)'.

Index: lib/readutmp.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/readutmp.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -p -u -r1.15 -r1.16
--- lib/readutmp.c      15 Sep 2003 22:34:18 -0000      1.15
+++ lib/readutmp.c      19 Apr 2004 20:12:23 -0000      1.16
@@ -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_
   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;
     }
 
Index: m4/readutmp.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/readutmp.m4,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -p -u -r1.3 -r1.4
--- m4/readutmp.m4      12 Sep 2003 19:38:19 -0000      1.3
+++ m4/readutmp.m4      19 Apr 2004 20:11:46 -0000      1.4
@@ -1,5 +1,5 @@
 # readutmp.m4 serial 3
-dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -58,5 +58,5 @@ $ac_includes_default
 # Prerequisites of lib/readutmp.c.
 AC_DEFUN([gl_PREREQ_READUTMP],
 [
-  :
+  AC_REQUIRE([gl_FUNC_FREE])
 ])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]