[Pntool-developers] SF.net SVN: pntool:[216] spnbox
Brought to you by:
compaqdrew,
miordache
From: <Ste...@us...> - 2009-08-14 21:47:13
|
Revision: 216 http://pntool.svn.sourceforge.net/pntool/?rev=216&view=rev Author: StephenCamp Date: 2009-08-14 21:47:00 +0000 (Fri, 14 Aug 2009) Log Message: ----------- Corrected minor bugs and memory leaks in most of the spnbox files. All files are now reported memory-leak-free after being run with the memwatch functions linked, except for a memory leak possibly related to type-3 matrix storage only. This leak is still under investigation. Modified Paths: -------------- spnbox/MemoryManager.c spnbox/asiph.c spnbox/avpr.c spnbox/deallocation.c spnbox/dp.c spnbox/extendedmatrix.c spnbox/fvpr.c spnbox/ilpadm.c spnbox/ipsolve.c spnbox/linenf.c spnbox/nltrans.c spnbox/reduce.c spnbox/tactn.c spnbox/tests/Makefile spnbox/tests/StructuredIO.c spnbox/tests/test-avpr.c spnbox/tests/test-dp.c spnbox/tests/test-extendedmatrix.txt spnbox/tests/test-fvpr.c spnbox/tests/test-linenf.c spnbox/tests/test-msplit.c Modified: spnbox/MemoryManager.c =================================================================== --- spnbox/MemoryManager.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/MemoryManager.c 2009-08-14 21:47:00 UTC (rev 216) @@ -78,7 +78,7 @@ int i; for (i = 0; i < mgr->nextm; i++) { - DeallocateMatrix(mgr->matrices[i]); + if (mgr->matrices[i]->type) DeallocateMatrix(mgr->matrices[i]); } free(mgr->matrices); mgr->matrices = 0; Modified: spnbox/asiph.c =================================================================== --- spnbox/asiph.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/asiph.c 2009-08-14 21:47:00 UTC (rev 216) @@ -102,6 +102,7 @@ } /*If MNS is empty, build it based on if there are any source transitions.*/ result = BuildResult(Dm, Dp, &data, newIndex); + FreeMemory(&mem); return result; } @@ -188,6 +189,8 @@ } if (data->MNS.type) DeallocateMatrix(&data->MNS); if (data->NS.type) DeallocateMatrix(&data->NS); + free(sourceF); + free(index); return result; } @@ -688,6 +691,7 @@ if (! newCount) { memset(&sx, 0, sizeof(matrix)); + FreeMemory(&memory); return sx; } /*Otherwise, build the actual list of non-null Dma/Dpa row indices.*/ @@ -797,6 +801,7 @@ AllocateMatrixType(2, &data->MNS, 0, NumberOfRows(*Dm)); } AllocateMatrixType(2, &data->NS, 0, NumberOfRows(*Dm)); + FreeMemory(&memory); return sx; } @@ -880,8 +885,6 @@ { actn_r result; result = actn(Dm, Dp, 0, 0, 0, 0, 0, 0); - ManageMatrix(mem, &result.Dma); - ManageMatrix(mem, &result.Dpa); if (result.Dmra.type) DeallocateMatrix(&result.Dmra); if (result.Dpra.type) DeallocateMatrix(&result.Dpra); @@ -889,6 +892,9 @@ **Dma = result.Dma; *Dpa = mmalloc(mem, sizeof(matrix)); **Dpa = result.Dpa; + ManageMatrix(mem, *Dma); + ManageMatrix(mem, *Dpa); + if (result.TA) free(result.TA); } return 1; Modified: spnbox/avpr.c =================================================================== --- spnbox/avpr.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/avpr.c 2009-08-14 21:47:00 UTC (rev 216) @@ -13,6 +13,7 @@ static int CheckParams(int* vector, int length, int mode, char** chr); static int GetVectorEl(void* vector, int i, int mode); static int GetBufferLength(void* vector, int length, int mode, char* chr, char* bl, char* el); +static void FinalFree(); char* avpr(void *vector, int length, int mode, char* chr, int option) { Modified: spnbox/deallocation.c =================================================================== --- spnbox/deallocation.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/deallocation.c 2009-08-14 21:47:00 UTC (rev 216) @@ -143,7 +143,7 @@ void DeallocateTactn(tactn_r *data) { - DeallocateTactn(data); + DeallocateActn(data); } void DeallocateIssiph(issiph_r *data) Modified: spnbox/dp.c =================================================================== --- spnbox/dp.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/dp.c 2009-08-14 21:47:00 UTC (rev 216) @@ -162,6 +162,8 @@ /*Mark for termination.*/ d.terminate = 1; } + DeallocateMatrix(&cons.L); + free(cons.B); DeallocateChkcons(&chkconsRes); } @@ -181,6 +183,7 @@ EnforceMarkingConstraints(&d); /*Build the useful places list: include all places initially.*/ + if (d.upl) free(d.upl); d.upCount = NumberOfRows(d.Dm); d.upl = tcalloc(d.upCount, sizeof(int)); for (i = 0; i < d.upCount; i++) @@ -464,7 +467,7 @@ fprintf(d->log, "The set Tx is:\nTx = %s", ListTransitions(d->TA, d->TACount)); } } - else if (d->state.perm) + else { fprintf(d->log, "guaranteed to enforce"); if (d->state.anetfail) @@ -480,7 +483,7 @@ } fprintf(d->log, "and may not be the least restrictive"); } - else if (d->state.unique) + if (d->state.perm && ! d->state.unique) { fprintf(d->log, "\nThe supervisor is the least restrictive Ta-liveness "); fprintf(d->log, "enforcing supervisor for\nTa = %s", ListTransitions(d->TA, d->TACount)); @@ -781,6 +784,7 @@ L, B or L0, B0.*/ if (chkconsRes.resCount) { + DeallocateChkcons(&chkconsRes); /*Find out whether these constraints should apply to the marking at all times or just to the initial marking.*/ if (DoConstraintsApplyToAll(d, &supervisRes, &a, currentSiphon)) @@ -852,12 +856,16 @@ { if (d->log) PrintConstraints(d, 0, 0, currentSiphon, -1, 0); } + /*If l has not been absorbed into something else, deallocate it here.*/ + if (l.type) DeallocateMatrix(&l); if (NumberOfRows(cons.L)) { DeallocateMatrix(&cons.L); free(cons.B); } } + DeallocateMatrix(&a); + free(currentSiphon); } /******************************************************************************* @@ -972,7 +980,7 @@ /*Find the number of independent places to use.*/ for (i = 0; i < d->ipCount; i++) { - if (d->ipl[i] > d->targetRows) break; + if (d->ipl[i] >= d->targetRows) break; } /*i now contains the number of independent places that we want to use. Update the total count and allocate memory.*/ @@ -1295,6 +1303,7 @@ /*Remove from the new siphons list those siphons which contain no useful places.*/ + free(possibleSiphons); j = 0; while (j < NumberOfColumns(d->S)) { @@ -1666,6 +1675,7 @@ /*Empty G and M.*/ if (d->G) free(d->G); + d->G = 0; if (d->M.type) DeallocateMatrix(&d->M); /*Initialize M to be the right size for an msplit.*/ @@ -2040,7 +2050,7 @@ void AddToIndexArray(int** array, int* length, int item) { int *newArray = tcalloc(*length + 1, sizeof(int)); - memcpy(newArray, *array, sizeof(int) * (*length)); + if (length) memcpy(newArray, *array, sizeof(int) * (*length)); newArray[(*length)++] = item; free(*array); *array = newArray; @@ -2052,7 +2062,7 @@ void AddToArray(int** array, int length, int item) { int* newArray = tcalloc(length + 1, sizeof(int)); - memcpy(newArray, *array, sizeof(int) * length); + if (length) memcpy(newArray, *array, sizeof(int) * length); newArray[length] = item; free(*array); *array = newArray; Modified: spnbox/extendedmatrix.c =================================================================== --- spnbox/extendedmatrix.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/extendedmatrix.c 2009-08-14 21:47:00 UTC (rev 216) @@ -260,6 +260,12 @@ m->ar[i - rows] = m->ar[i]; } m->nr -= rows; + /*If we have removed all rows, deallocate the ar pointer.*/ + if (! m->nr) + { + free(m->ar); + m->ar = 0; + } } else { Modified: spnbox/fvpr.c =================================================================== --- spnbox/fvpr.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/fvpr.c 2009-08-14 21:47:00 UTC (rev 216) @@ -56,7 +56,7 @@ { free(buffer); bufferLength = newBufferLength; - buffer = calloc(bufferLength, sizeof(char)); + buffer = tcalloc(bufferLength, sizeof(char)); } buffer[0] = '\0'; if (! length) return buffer; Modified: spnbox/ilpadm.c =================================================================== --- spnbox/ilpadm.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/ilpadm.c 2009-08-14 21:47:00 UTC (rev 216) @@ -124,6 +124,7 @@ an additional constraint. Test for them.*/ if (RedoLP1(L, b, &LPSolution, i)) { + DeallocateIpsolve(&LPSolution); /*Build the alternate linear programming problem and solve it.*/ BuildLP1Alternate(&M2, &CDeltas, L, Tuc, TucCount, Tuo, TuoCount, i); LPSolution = ipsolve(&M2, N2, Cost, 0, 0, LoBounds, CType2); Modified: spnbox/ipsolve.c =================================================================== --- spnbox/ipsolve.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/ipsolve.c 2009-08-14 21:47:00 UTC (rev 216) @@ -118,7 +118,7 @@ { lp.Cost[i] = 0; } - free(lpresult.solution); + free(lpresult.solution); lpresult = ipslv(lp.Cost, lp.L, lp.B, lp.Constraints, lp.Variables, lp.IntList, lp.HiBound, lp.LoBound, lp.ctype); } @@ -136,6 +136,7 @@ } } } + if (lpresult.solution) free(lpresult.solution); } else { @@ -253,7 +254,7 @@ *ColKeys = mcalloc(mem, Cols, sizeof(int)); HiBoundF = tcalloc(Cols, sizeof(int)); LoBoundF = tcalloc(Cols, sizeof(int)); - result->res = tcalloc(Cols, sizeof(double)); + result->res = tcalloc(Cols, sizeof(double)); for (i = 0; i < Cols; i++) { /*Fill the finite bounds indicators with the appropriate value. We reserve a Modified: spnbox/linenf.c =================================================================== --- spnbox/linenf.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/linenf.c 2009-08-14 21:47:00 UTC (rev 216) @@ -277,15 +277,12 @@ /*Enforce the constraints.*/ EnfResult = linenf(&NewDm, &NewDp, &AdmResult.La, b ? AdmResult.ba : 0, Newm0, &NewF, 0, 0, 0, 0, 0); - ManageMatrix(&RowMemory, &EnfResult.Dfm); - ManageMatrix(&RowMemory, &EnfResult.Dfp); - ManageMemory(&RowMemory, EnfResult.ms0); - ManageMemory(&RowMemory, EnfResult.dhow); - if (b) ManageMemory(&RowMemory, EnfResult.bf); /*Collapse the enforced net back to applying to the original problem and store the results in the return structure.*/ CollapseNet(i, &EnfResult, &Transform, &Ret, Places, Transitions); + + DeallocateLinenf(&EnfResult); } else { @@ -304,15 +301,10 @@ /*Enforce the constraints.*/ EnfResult = linenf(Dm, Dp, &NewL, b ? b + i : 0, m0, &NewF, &NewC, 0, 0, 0, 0); - ManageMatrix(&RowMemory, &EnfResult.Dfm); - ManageMatrix(&RowMemory, &EnfResult.Dfp); - ManageMatrix(&RowMemory, &EnfResult.Cf); - ManageMemory(&RowMemory, EnfResult.ms0); - ManageMemory(&RowMemory, EnfResult.dhow); - if (b) ManageMemory(&RowMemory, EnfResult.bf); /*Copy the enforced constraints into the appropriate places.*/ - CollapseNet(i, &EnfResult, 0, &Ret, Places, Transitions); + CollapseNet(i, &EnfResult, 0, &Ret, Places, Transitions); + DeallocateLinenf(&EnfResult); } //Free memory FreeMemory(&RowMemory); Modified: spnbox/nltrans.c =================================================================== --- spnbox/nltrans.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/nltrans.c 2009-08-14 21:47:00 UTC (rev 216) @@ -65,7 +65,7 @@ { cov[i] = 1; } - } + } /*Check. If all elements of cov are nonzero, we want to exit the loop.*/ fContinue = 0; for (i = 0; i < covCount; i++) @@ -77,6 +77,7 @@ } } } + DeallocateIpsolve(&solution); } while (fContinue); /*The return value is the logic inverse of cov.*/ Modified: spnbox/reduce.c =================================================================== --- spnbox/reduce.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/reduce.c 2009-08-14 21:47:00 UTC (rev 216) @@ -65,6 +65,7 @@ KeepRow[i] = 1; Rows++; } + DeallocateChkcons(&ChkResult); /*Otherwise the row is redundant. Leave it nulled out.*/ } Modified: spnbox/tactn.c =================================================================== --- spnbox/tactn.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/tactn.c 2009-08-14 21:47:00 UTC (rev 216) @@ -181,12 +181,17 @@ /*If we get a valid solution, then free memory and return false.*/ if (! strcmp(result.mhow, HOW_OK)) { + DeallocateIpsolve(&result); free(IntList); free(B); DeallocateMatrix(&Dx); DeallocateMatrix(&dx); return 0; } + else + { + DeallocateIpsolve(&result); + } } //If we get through all transition without returning false, return true. free(IntList); Modified: spnbox/tests/Makefile =================================================================== --- spnbox/tests/Makefile 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/tests/Makefile 2009-08-14 21:47:00 UTC (rev 216) @@ -4,6 +4,10 @@ #clean cleans the test routine executables and intermediate files. #<functionname> is the name of an spnbox function. This builds the test routines for that function. +#To remove the memwatch memory debugging routines: +#Make MEMWCOMP equal to COMPILER (removing the include and define options) +#Remove "memwatch.o" from the list of COMMON dependencies. + COMPILER=gcc -g MEMWCOMP=$(COMPILER) -include string.h -include ../../third-party/memwatch-2.71/memwatch.h -DMEMWATCH -DMEMWATCH_STDIO #The dependencies common to all test executables. @@ -42,8 +46,8 @@ $(COMPILER) -o extendedmatrix.exe test-extendedmatrix.o $(EXTENDEDMATRIX) $(COMMON) fvpr: test-fvpr.o $(FVPR) $(COMMON) $(COMPILER) -o fvpr.exe test-fvpr.o $(FVPR) $(COMMON) -ipslv: test-ipslv.o $(IPSLV) - $(COMPILER) -o ipslv.exe test-ipslv.o $(IPSLV) +ipslv: test-ipslv.o $(IPSLV) $(COMMON) + $(COMPILER) -o ipslv.exe test-ipslv.o $(IPSLV) $(COMMON) ipsolve: test-ipsolve.o $(COMMON) $(IPSOLVE) $(COMPILER) -o ipsolve.exe test-ipsolve.o $(COMMON) $(IPSOLVE) isadm: test-isadm.o $(ISADM) Modified: spnbox/tests/StructuredIO.c =================================================================== --- spnbox/tests/StructuredIO.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/tests/StructuredIO.c 2009-08-14 21:47:00 UTC (rev 216) @@ -380,6 +380,7 @@ } } va_end(args); + FreeMemory(&memory); } int* ReadIntArray(FILE* file, int* length) Modified: spnbox/tests/test-avpr.c =================================================================== --- spnbox/tests/test-avpr.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/tests/test-avpr.c 2009-08-14 21:47:00 UTC (rev 216) @@ -58,6 +58,7 @@ ShowOffset[0] = '\0'; printf("-------------------------------------------------------------------------------\n"); } + FreeMemory(&mem); return 1; } \ No newline at end of file Modified: spnbox/tests/test-dp.c =================================================================== --- spnbox/tests/test-dp.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/tests/test-dp.c 2009-08-14 21:47:00 UTC (rev 216) @@ -67,5 +67,6 @@ WriteLog[0] = '\0'; EnforceLive[0] = '\0'; } + FreeMemory(&mem); return 0; } Modified: spnbox/tests/test-extendedmatrix.txt =================================================================== --- spnbox/tests/test-extendedmatrix.txt 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/tests/test-extendedmatrix.txt 2009-08-14 21:47:00 UTC (rev 216) @@ -138,7 +138,7 @@ columns 1 optimization yes done - +quit echo Problem 13. Null row insertion, unoptimized speedtest. operation InsertNullRows size 20 Modified: spnbox/tests/test-fvpr.c =================================================================== --- spnbox/tests/test-fvpr.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/tests/test-fvpr.c 2009-08-14 21:47:00 UTC (rev 216) @@ -59,5 +59,6 @@ printf("-------------------------------------------------------------------------------\n"); } + FreeMemory(&mem); return 0; } Modified: spnbox/tests/test-linenf.c =================================================================== --- spnbox/tests/test-linenf.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/tests/test-linenf.c 2009-08-14 21:47:00 UTC (rev 216) @@ -40,9 +40,6 @@ /*Do the constraint enforcement.*/ sol = linenf(IFilled[1] ? &Dm : 0, IFilled[2] ? &Dp : 0, IFilled[5] ? &L : 0, IFilled[8] ? b : 0, IFilled[9] ? m0 : 0, IFilled[6] ? &F : 0, IFilled[7] ? &C : 0, IFilled[3] ? TucCount : 0, Tuc, IFilled[4] ? TuoCount : 0, Tuo); - ManageMatrix(&memory, &sol.Dfm); - ManageMatrix(&memory, &sol.Dfp); - /*Get the list of which output parameters are present for display. Also manage memory. (Defaults to nothing present)*/ memset(OFilled, 0, sizeof(int) * 8); Modified: spnbox/tests/test-msplit.c =================================================================== --- spnbox/tests/test-msplit.c 2009-08-14 08:10:08 UTC (rev 215) +++ spnbox/tests/test-msplit.c 2009-08-14 21:47:00 UTC (rev 216) @@ -60,14 +60,16 @@ int* Ret = 0; /*Clear the mask initially*/ memset(Mask, 0, sizeof(int) * 9); - /*Manage the memory and prepare the display mask while we're at it.*/ - ManageMatrix(mem, &Data->Dfm); - ManageMatrix(mem, &Data->Dfp); - ManageMatrix(mem, &Data->Df); - Mask[0] = 1; - Mask[1] = 1; - Mask[2] = 1; - CleanUpIncidence(mem, &Data->Df, &Data->Dfm, &Data->Dfp, Mask); + /*Prepare the display mask while we're at it.*/ + if (HasSelfLoops(&Data->Dfm, &Data->Dfp)) + { + Mask[1] = 1; + Mask[2] = 1; + } + else + { + Mask[0] = 1; + } if (NumberOfRows(Data->Mf)) { Mask[3] = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |