From: Nickolai Zeldovich Date: Wed, 20 Nov 2002 03:24:47 +0000 (+0000) Subject: STABLE12-misc-dynroot-cleanup-20021119 X-Git-Tag: openafs-stable-1_2_8~20 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=f89e2d9a443b24639055ba321405615afc5a3b67;p=packages%2Fo%2Fopenafs.git STABLE12-misc-dynroot-cleanup-20021119 Fix a memory leak in the dynroot directory creation process and factor out common code to compute directory size. (cherry picked from commit 6af0e344af39d15c8816b2acd86b785f991898b5) --- diff --git a/src/afs/afs_dynroot.c b/src/afs/afs_dynroot.c index b90d968bc..107b3a8bd 100644 --- a/src/afs/afs_dynroot.c +++ b/src/afs/afs_dynroot.c @@ -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); }