Source-Changes-HG archive

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

[src/trunk]: src/libexec/lfs_cleanerd Take care of memory leaks



details:   https://anonhg.NetBSD.org/src/rev/4730661848a5
branches:  trunk
changeset: 480700:4730661848a5
user:      perseant <perseant%NetBSD.org@localhost>
date:      Tue Jan 18 08:02:30 2000 +0000

description:
Take care of memory leaks

diffstat:

 libexec/lfs_cleanerd/cleanerd.c |  22 ++++++++++++++--------
 libexec/lfs_cleanerd/library.c  |   7 ++++---
 libexec/lfs_cleanerd/print.c    |  10 +++++++---
 3 files changed, 25 insertions(+), 14 deletions(-)

diffs (127 lines):

diff -r 6025375a8872 -r 4730661848a5 libexec/lfs_cleanerd/cleanerd.c
--- a/libexec/lfs_cleanerd/cleanerd.c   Tue Jan 18 07:45:04 2000 +0000
+++ b/libexec/lfs_cleanerd/cleanerd.c   Tue Jan 18 08:02:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cleanerd.c,v 1.17 1999/11/09 20:33:37 perseant Exp $   */
+/*     $NetBSD: cleanerd.c,v 1.18 2000/01/18 08:02:30 perseant Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)cleanerd.c 8.5 (Berkeley) 6/10/95";
 #else
-__RCSID("$NetBSD: cleanerd.c,v 1.17 1999/11/09 20:33:37 perseant Exp $");
+__RCSID("$NetBSD: cleanerd.c,v 1.18 2000/01/18 08:02:30 perseant Exp $");
 #endif
 #endif /* not lint */
 
@@ -421,6 +421,8 @@
        struct seglist *segs, *sp;
        long int to_clean, cleaned_bytes;
        unsigned long i, j, total;
+       struct rusage ru;
+       int error;
 
        if ((segs =
            malloc(fsp->fi_lfs.lfs_nseg * sizeof(struct seglist))) == NULL) {
@@ -440,8 +442,10 @@
                sp++;
                i--;
        }
-       if(j > nsegs)
+       if(j > nsegs) {
+               free(segs);
                return;
+       }
 
        /* If we relly need to clean a lot, do it now */
        if(fsp->fi_cip->clean < 2*MIN_FREE_SEGS)
@@ -496,11 +500,13 @@
        }
        free(segs);
        if(debug) {
-               struct rusage ru;
-
-               getrusage(RUSAGE_SELF,&ru);
-               syslog(LOG_DEBUG,"Current usage: maxrss=%ld, idrss=%ld",
-                      ru.ru_maxrss,ru.ru_idrss);
+               error=getrusage(RUSAGE_SELF,&ru);
+               if(error) {
+                       syslog(LOG_INFO,"getrusage returned error: %m");
+               } else {
+                       syslog(LOG_DEBUG,"Current usage: maxrss=%ld, idrss=%ld, isrss=%ld",
+                              ru.ru_maxrss,ru.ru_idrss,ru.ru_isrss);
+               }
        }
 }
 
diff -r 6025375a8872 -r 4730661848a5 libexec/lfs_cleanerd/library.c
--- a/libexec/lfs_cleanerd/library.c    Tue Jan 18 07:45:04 2000 +0000
+++ b/libexec/lfs_cleanerd/library.c    Tue Jan 18 08:02:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: library.c,v 1.14 1999/10/07 18:26:58 perseant Exp $    */
+/*     $NetBSD: library.c,v 1.15 2000/01/18 08:02:30 perseant Exp $    */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)library.c  8.3 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: library.c,v 1.14 1999/10/07 18:26:58 perseant Exp $");
+__RCSID("$NetBSD: library.c,v 1.15 2000/01/18 08:02:30 perseant Exp $");
 #endif
 #endif /* not lint */
 
@@ -244,7 +244,7 @@
 
        if (use_mmap && file_stat.st_size == fsp->fi_ifile_length) {
                /* (void) close(fid); */
-                free(ifile_name); /* XXX KS */
+                free(ifile_name);
                return;
        }
 
@@ -616,6 +616,7 @@
        }
        if (cksum ((void *)datap, nblocks * sizeof(u_long)) != ssp->ss_datasum) {
                 syslog(LOG_DEBUG, "Bad data checksum");
+               free(datap);
                return 0;
         }
 #endif
diff -r 6025375a8872 -r 4730661848a5 libexec/lfs_cleanerd/print.c
--- a/libexec/lfs_cleanerd/print.c      Tue Jan 18 07:45:04 2000 +0000
+++ b/libexec/lfs_cleanerd/print.c      Tue Jan 18 08:02:30 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: print.c,v 1.7 1999/03/10 00:57:16 perseant Exp $       */
+/*     $NetBSD: print.c,v 1.8 2000/01/18 08:02:31 perseant Exp $       */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "from: @(#)print.c      8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: print.c,v 1.7 1999/03/10 00:57:16 perseant Exp $");
+__RCSID("$NetBSD: print.c,v 1.8 2000/01/18 08:02:31 perseant Exp $");
 #endif
 #endif /* not lint */
 
@@ -83,10 +83,14 @@
 
        blk=0;
        datap = (u_long *)malloc((lfsp->lfs_ssize*lfsp->lfs_frag) * sizeof(u_long));
+       if(datap==NULL)
+               return(-1);
 
        if (sp->ss_sumsum != (ck = cksum(&sp->ss_datasum, 
-           LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum))))
+           LFS_SUMMARY_SIZE - sizeof(sp->ss_sumsum)))) {
+               free(datap);
                return(-1);
+       }
 
        if (flags & DUMP_SUM_HEADER) {
                 syslog(LOG_DEBUG, "    %s0x%X\t%s%d\t%s%d\n    %s0x%X\t%s0x%X",



Home | Main Index | Thread Index | Old Index