From e946fcf7691407a4f9c5985da9bd65095ab04295 Mon Sep 17 00:00:00 2001 From: Marc Dionne Date: Sat, 31 Oct 2009 08:54:52 -0400 Subject: [PATCH] Fix memory allocation warnings at shutdown At shutdown we check for unfreed memory allocated with AllocSmallSpace and AllocLargeSpace and complain in the syslog if there are dangling pieces. This patch takes care of a few cases that always showed up as warnings, even after a simple start-stop of the client. - The cacheInode file needs to be closed before the checks, since it uses a large piece for its struct file. - The ICL logging code allocates 6 small pieces that are never freed. Add a shutdown_icl() function that releases everything. While we're at it, correct one place where we allocated with afs_osi_Alloc but freed with osi_FreeSmallSpace, confusing our accounting. Change-Id: I4c28c848f155dec9d89e6199cde34209227ca5c9 Reviewed-on: http://gerrit.openafs.org/758 Reviewed-by: Simon Wilkinson Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear Reviewed-on: http://gerrit.openafs.org/767 --- src/afs/afs_call.c | 50 ++++++++++++++++++++++++++++++++++------ src/afs/afs_prototypes.h | 1 + 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/afs/afs_call.c b/src/afs/afs_call.c index bb0205fc9..0b6011d55 100644 --- a/src/afs/afs_call.c +++ b/src/afs/afs_call.c @@ -1894,6 +1894,20 @@ afs_shutdown(void) shutdown_bufferpackage(); shutdown_cache(); shutdown_osi(); + /* + * Close file only after daemons which can write to it are stopped. + * Need to close before the osinet shutdown to avoid failing check + * for dangling memory allocations. + */ + if (afs_cacheInodep) { /* memcache won't set this */ + osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */ + afs_cacheInodep = 0; + } + /* + * Shutdown the ICL logs - needed to free allocated memory space and avoid + * warnings from shutdown_osinet + */ + shutdown_icl(); shutdown_osinet(); shutdown_osifile(); shutdown_vnodeops(); @@ -1911,12 +1925,6 @@ afs_shutdown(void) */ afs_warn(" ALL allocated tables\n"); - /* Close file only after daemons which can write to it are stopped. */ - if (afs_cacheInodep) { /* memcache won't set this */ - osi_UFSClose(afs_cacheInodep); /* Since we always leave it open */ - afs_cacheInodep = 0; - } - afs_shuttingdown = 0; return; /* Just kill daemons for now */ @@ -3109,7 +3117,7 @@ afs_icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp, if (flags & ICL_CRSET_FLAG_PERSISTENT) states |= ICL_SETF_PERSISTENT; - setp = (struct afs_icl_set *)afs_osi_Alloc(sizeof(struct afs_icl_set)); + setp = (struct afs_icl_set *)osi_AllocSmallSpace(sizeof(struct afs_icl_set)); memset((caddr_t) setp, 0, sizeof(*setp)); setp->refCount = 1; if (states & ICL_SETF_FREED) @@ -3414,3 +3422,31 @@ afs_icl_SetSetStat(struct afs_icl_set *setp, int op) ReleaseWriteLock(&setp->lock); return code; } + +/* Function called at shutdown - zap everything */ +void +shutdown_icl(void) +{ + struct afs_icl_log *logp; + struct afs_icl_set *setp; + + setp = afs_icl_FindSet("cm"); + if (setp) { + /* Release the reference from Find, and the initial one */ + afs_icl_SetFree(setp); + afs_icl_SetFree(setp); + } + setp = afs_icl_FindSet("cmlongterm"); + if (setp) { + /* Release the reference from Find, and the initial one */ + afs_icl_SetFree(setp); + afs_icl_SetFree(setp); + } + logp = afs_icl_FindLog("cmfx"); + if (logp) { + /* Release the reference from Find, and the initial one */ + afs_icl_LogFree(logp); + afs_icl_LogFree(logp); + } + return 0; +} diff --git a/src/afs/afs_prototypes.h b/src/afs/afs_prototypes.h index 7ba69225c..5ff1e4903 100644 --- a/src/afs/afs_prototypes.h +++ b/src/afs/afs_prototypes.h @@ -116,6 +116,7 @@ extern int afs_icl_Event0(register struct afs_icl_set *setp, extern void afs_icl_AppendRecord(register struct afs_icl_log *logp, afs_int32 op, afs_int32 types, long p1, long p2, long p3, long p4); +extern void shutdown_icl(void); extern int afs_CheckInit(void); extern void afs_shutdown(void); -- 2.39.5