]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
STABLE12-misc-dynroot-cleanup-20021119
authorNickolai Zeldovich <kolya@mit.edu>
Wed, 20 Nov 2002 03:24:47 +0000 (03:24 +0000)
committerDerrick Brashear <shadow@dementia.org>
Wed, 20 Nov 2002 03:24:47 +0000 (03:24 +0000)
Fix a memory leak in the dynroot directory creation process and
factor out common code to compute directory size.

(cherry picked from commit 6af0e344af39d15c8816b2acd86b785f991898b5)

src/afs/afs_dynroot.c

index b90d968bcf211fc98b3969f5d4f698dac85d46bb..107b3a8bd3810adee82b4e1c02a0e19a539ffadf 100644 (file)
@@ -125,6 +125,23 @@ afs_IsDynroot(avc)
     return afs_IsDynrootFid(&avc->fid);
 }
 
+/*
+ * Given the current page and chunk pointers in a directory, adjust them
+ * appropriately so that the given file name can be appended.  Used for
+ * computing the size of a directory.
+ */
+static void afs_dynroot_computeDirEnt(char *name, int *curPageP, int *curChunkP)
+{
+    int esize;
+
+    esize = afs_dir_NameBlobs(name);
+    if (*curChunkP + esize > EPP) {
+       *curPageP += 1;
+       *curChunkP = 1;
+    }
+    *curChunkP += esize;
+}
+
 /*
  * Add directory entry by given name to a directory.  Assumes the
  * caller has allocated the directory to be large enough to hold
@@ -207,7 +224,7 @@ afs_RefreshDynroot()
     int cellidx, maxcellidx, i;
     struct cell *c;
     int curChunk, curPage;
-    int dirSize, sizeOfCurEntry;
+    int dirSize, sizeOfCurEntry, dotLen;
     char *newDir, *dotCell;
     struct DirHeader *dirHeader;
     struct PageHeader *pageHeader;
@@ -243,7 +260,8 @@ afs_RefreshDynroot()
        }
        curChunk += sizeOfCurEntry;
 
-       dotCell = afs_osi_Alloc(strlen(c->cellName) + 2);
+       dotLen = strlen(c->cellName) + 2;
+       dotCell = afs_osi_Alloc(dotLen);
        strcpy(dotCell, ".");
        strcat(dotCell, c->cellName);
        sizeOfCurEntry = afs_dir_NameBlobs(dotCell);
@@ -253,6 +271,7 @@ afs_RefreshDynroot()
        }
        curChunk += sizeOfCurEntry;
 
+       afs_osi_Free(dotCell, dotLen);
        afs_PutCell(c, READ_LOCK);
     }
 
@@ -301,7 +320,8 @@ afs_RefreshDynroot()
        c = afs_GetCellByIndex(cellidx, READ_LOCK, 0 /* don't refresh */);
        if (!c) continue;
 
-       dotCell = afs_osi_Alloc(strlen(c->cellName) + 2);
+       dotLen = strlen(c->cellName) + 2;
+       dotCell = afs_osi_Alloc(dotLen);
        strcpy(dotCell, ".");
        strcat(dotCell, c->cellName);
        afs_dynroot_addDirEnt(dirHeader, &curPage, &curChunk,
@@ -310,6 +330,8 @@ afs_RefreshDynroot()
                              dotCell, VNUM_FROM_CIDX_RW(cellidx, 1));
 
        if (!(c->states & CAlias)) linkCount += 2;
+
+       afs_osi_Free(dotCell, dotLen);
        afs_PutCell(c, READ_LOCK);
     }