Source-Changes-HG archive

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

[src/trunk]: src/sys/lib/libsa Rework previous (1.24) change. Rather than de...



details:   https://anonhg.NetBSD.org/src/rev/ecc96e59b99a
branches:  trunk
changeset: 790447:ecc96e59b99a
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Fri Oct 11 16:30:31 2013 +0000

description:
Rework previous (1.24) change.  Rather than depending on the
file's flags to decide if decompress cleanup is needed, just
check to see if the open() allocated the 'struct sd *' used for
decompression.

This fixes recent problem where presence of a "load=ffs" command
in my /boot.cfg resulted in a "heap full" error at boot time.

OK martin@

diffstat:

 sys/lib/libsa/cread.c |  17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diffs (56 lines):

diff -r d19152a3df45 -r ecc96e59b99a sys/lib/libsa/cread.c
--- a/sys/lib/libsa/cread.c     Fri Oct 11 03:37:08 2013 +0000
+++ b/sys/lib/libsa/cread.c     Fri Oct 11 16:30:31 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cread.c,v 1.24 2013/04/14 22:23:28 martin Exp $        */
+/*     $NetBSD: cread.c,v 1.25 2013/10/11 16:30:31 pgoyette Exp $      */
 
 /*
  * Copyright (c) 1996
@@ -259,6 +259,7 @@
        int fd;
        struct sd *s = 0;
 
+       ss[fd] = NULL;
        if (((fd = oopen(fname, mode)) == -1) || (mode != 0))
                /* compression only for read */
                return fd;
@@ -284,6 +285,7 @@
 errout:
        if (s != 0)
                dealloc(s, sizeof(struct sd));
+       ss[fd] = NULL;
        oclose(fd);
        return -1;
 }
@@ -291,7 +293,6 @@
 int
 close(int fd)
 {
-       struct open_file *f;
        struct sd *s;
 
 #if !defined(LIBSA_NO_FD_CHECKING)
@@ -300,17 +301,15 @@
                return -1;
        }
 #endif
-       f = &files[fd];
-
-       if ((f->f_flags & (F_READ|F_WRITE)) == F_READ)
-               return oclose(fd);
 
        s = ss[fd];
 
-       inflateEnd(&(s->stream));
+       if (s != NULL) {
+               inflateEnd(&(s->stream));
 
-       dealloc(s->inbuf, Z_BUFSIZE);
-       dealloc(s, sizeof(struct sd));
+               dealloc(s->inbuf, Z_BUFSIZE);
+               dealloc(s, sizeof(struct sd));
+       }
 
        return oclose(fd);
 }



Home | Main Index | Thread Index | Old Index