]> git.pond.sub.org Git - empserver/commitdiff
Make ef_close() set fids later, so it's cleaned up on error
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 28 Apr 2011 18:52:37 +0000 (20:52 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 25 Jun 2011 14:50:06 +0000 (16:50 +0200)
Just for cleanliness.

src/lib/common/file.c

index 3c00b3e09509d6280397c8d029e9ca0adb3d21dd..31ecc260b888729b0437afbd123839e50cb28fa7 100644 (file)
@@ -74,7 +74,7 @@ int
 ef_open(int type, int how, int nelt)
 {
     struct empfile *ep;
-    int oflags, fd, fsiz, nslots;
+    int oflags, fd, fsiz, fids, nslots;
 
     if (ef_check(type) < 0)
        return 0;
@@ -104,10 +104,10 @@ ef_open(int type, int how, int nelt)
        close(fd);
        return 0;
     }
-    ep->fids = fsiz / ep->size;
-    if (nelt >= 0 && nelt != ep->fids) {
+    fids = fsiz / ep->size;
+    if (nelt >= 0 && nelt != fids) {
        logerror("Can't open %s (got %d records instead of %d)",
-                ep->file, ep->fids, nelt);
+                ep->file, fids, nelt);
        close(fd);
        return 0;
     }
@@ -116,7 +116,7 @@ ef_open(int type, int how, int nelt)
     if (ep->flags & EFF_STATIC) {
        /* ep->cache already points to space for ep->csize elements */
        if (how & EFF_MEM) {
-           if (ep->fids > ep->csize) {
+           if (fids > ep->csize) {
                logerror("Can't open %s (file larger than %d records)",
                         ep->file, ep->csize);
                close(fd);
@@ -127,7 +127,7 @@ ef_open(int type, int how, int nelt)
        if (CANT_HAPPEN(ep->cache))
            free(ep->cache);
        if (how & EFF_MEM)
-           nslots = ep->fids;
+           nslots = fids;
        else
            nslots = blksize(fd) / ep->size;
        if (!ef_realloc_cache(ep, nslots)) {
@@ -138,12 +138,13 @@ ef_open(int type, int how, int nelt)
     }
     ep->baseid = 0;
     ep->cids = 0;
+    ep->fids = fids;
     ep->flags = (ep->flags & EFF_IMMUTABLE) | (how & ~EFF_CREATE);
     ep->fd = fd;
 
     /* map file into cache */
-    if ((how & EFF_MEM) && ep->fids) {
-       if (fillcache(ep, 0) != ep->fids) {
+    if ((how & EFF_MEM) && fids) {
+       if (fillcache(ep, 0) != fids) {
            ep->cids = 0;       /* prevent cache flush */
            ef_close(type);
            return 0;