From 1cce2e35b06b54469dd627454c0f58818ff3523a Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 29 Apr 2008 12:21:52 +0200 Subject: removed loadbale module leak - moved netstrms, netstrm and nssel into a single loadble module because they belong together - fixed "loadbale module leak" --- runtime/nssel.c | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) (limited to 'runtime/nssel.c') diff --git a/runtime/nssel.c b/runtime/nssel.c index 793da9dc..50228208 100644 --- a/runtime/nssel.c +++ b/runtime/nssel.c @@ -44,8 +44,6 @@ #include "netstrm.h" #include "nssel.h" -MODULE_TYPE_LIB - /* static data */ DEFobjStaticHelpers DEFobjCurrIf(glbl) @@ -59,6 +57,8 @@ DEFobjCurrIf(glbl) * a nssel driver. So we simply append "sel" to the nsd driver name: This, * of course, means that the driver name must match these rules, but that * shouldn't be a real problem. + * WARNING: this code is mostly identical to similar code in + * netstrms.c - TODO: abstract it and move it to some common place. * rgerhards, 2008-04-28 */ static rsRetVal @@ -68,11 +68,12 @@ loadDrvr(nssel_t *pThis) uchar *pBaseDrvrName; uchar szDrvrName[48]; /* 48 shall be large enough */ - pBaseDrvrName = pThis->pDrvrName; + pBaseDrvrName = pThis->pBaseDrvrName; if(pBaseDrvrName == NULL) /* if no drvr name is set, use system default */ pBaseDrvrName = glbl.GetDfltNetstrmDrvr(); if(snprintf((char*)szDrvrName, sizeof(szDrvrName), "lmnsdsel_%s", pBaseDrvrName) == sizeof(szDrvrName)) ABORT_FINALIZE(RS_RET_DRVRNAME_TOO_LONG); + CHKmalloc(pThis->pDrvrName = (uchar*) strdup((char*)szDrvrName)); pThis->Drvr.ifVersion = nsdCURR_IF_VERSION; /* The pDrvrName+2 below is a hack to obtain the object name. It @@ -82,7 +83,13 @@ loadDrvr(nssel_t *pThis) * enough. -- rgerhards, 2008-04-18 */ CHKiRet(obj.UseObj(__FILE__, szDrvrName+2, szDrvrName, (void*) &pThis->Drvr)); + finalize_it: + if(iRet != RS_RET_OK) { + if(pThis->pDrvrName != NULL) + free(pThis->pDrvrName); + pThis->pDrvrName = NULL; + } RETiRet; } @@ -97,6 +104,15 @@ BEGINobjDestruct(nssel) /* be sure to specify the object type also in END and CO CODESTARTobjDestruct(nssel) if(pThis->pDrvrData != NULL) pThis->Drvr.Destruct(&pThis->pDrvrData); + + /* and now we must release our driver, if we got one. We use the presence of + * a driver name string as load indicator (because we also need that string + * to release the driver + */ + if(pThis->pDrvrName != NULL) { + obj.ReleaseObj(__FILE__, pThis->pDrvrName+2, pThis->pDrvrName, (void*) &pThis->Drvr); + free(pThis->pDrvrName); + } ENDobjDestruct(nssel) @@ -207,29 +223,5 @@ BEGINObjClassInit(nssel, 1, OBJ_IS_CORE_MODULE) /* class, version */ /* set our own handlers */ ENDObjClassInit(nssel) - - -/* --------------- here now comes the plumbing that makes us a library module --------------- */ - - -BEGINmodExit -CODESTARTmodExit - nsselClassExit(); -ENDmodExit - - -BEGINqueryEtryPt -CODESTARTqueryEtryPt -CODEqueryEtryPt_STD_LIB_QUERIES -ENDqueryEtryPt - - -BEGINmodInit() -CODESTARTmodInit - *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ - - /* Initialize all classes that are in our module - this includes ourselfs */ - CHKiRet(nsselClassInit(pModInfo)); /* must be done after tcps_sess, as we use it */ -ENDmodInit /* vi:set ai: */ -- cgit