diff --git a/buddy/src/fdd.c b/buddy/src/fdd.c index 1c108548d..2142d9498 100644 --- a/buddy/src/fdd.c +++ b/buddy/src/fdd.c @@ -143,9 +143,10 @@ int fdd_extdomain(int *dom, int num) { fdvaralloc += (num > fdvaralloc) ? num : fdvaralloc; - domain = (Domain*)realloc(domain, sizeof(Domain)*fdvaralloc); - if (domain == NULL) + Domain* tmp_ptr = (Domain*)realloc(domain, sizeof(Domain)*fdvaralloc); + if (tmp_ptr == NULL) return bdd_error(BDD_MEMORY); + domain = tmp_ptr; } } @@ -219,9 +220,10 @@ int fdd_overlapdomain(int v1, int v2) { fdvaralloc += fdvaralloc; - domain = (Domain*)realloc(domain, sizeof(Domain)*fdvaralloc); - if (domain == NULL) + Domain* tmp_ptr = (Domain*)realloc(domain, sizeof(Domain)*fdvaralloc); + if (tmp_ptr == NULL) return bdd_error(BDD_MEMORY); + domain = tmp_ptr; } d = &domain[fdvarnum]; diff --git a/buddy/src/imatrix.c b/buddy/src/imatrix.c index eb21ea49e..9e482941f 100644 --- a/buddy/src/imatrix.c +++ b/buddy/src/imatrix.c @@ -46,7 +46,7 @@ imatrix* imatrixNew(int size) { imatrix *mtx = NEW(imatrix,1); int n,m; - + if (!mtx) return NULL; @@ -62,6 +62,7 @@ imatrix* imatrixNew(int size) { for (m=0 ; mrows[m]); + free(mtx->rows); free(mtx); return NULL; } @@ -96,7 +97,7 @@ void imatrixFPrint(imatrix *mtx, FILE *ofile) for (x=0 ; xsize ; x++) fprintf(ofile, "%c", x < 26 ? (x+'a') : (x-26)+'A'); fprintf(ofile, "\n"); - + for (y=0 ; ysize ; y++) { fprintf(ofile, "%2d %c", y, y < 26 ? (y+'a') : (y-26)+'A'); @@ -141,7 +142,7 @@ void main(void) imatrixSet(m,0,2); imatrixSet(m,8,8); imatrixSet(m,15,15); - + imatrixPrint(m); } #endif diff --git a/buddy/src/kernel.c b/buddy/src/kernel.c index f7a8e2de8..97174a6ef 100644 --- a/buddy/src/kernel.c +++ b/buddy/src/kernel.c @@ -1,5 +1,5 @@ /*======================================================================== - Copyright (C) 1996-2002 by Jorn Lind-Nielsen + Copyright (C) 1996-2002, 2015 by Jorn Lind-Nielsen All rights reserved Permission is hereby granted, without written agreement and without @@ -334,22 +334,25 @@ int bdd_setvarnum(int num) } else { - if (__unlikely((bddvarset = - (BDD*)realloc(bddvarset,sizeof(BDD)*num*2)) == NULL)) + BDD* tmp_ptr = (BDD*)realloc(bddvarset,sizeof(BDD)*num*2); + if (__unlikely(tmp_ptr == NULL)) return bdd_error(BDD_MEMORY); - if (__unlikely((bddlevel2var = - (int*)realloc(bddlevel2var,sizeof(int)*(num+1))) == NULL)) + bddvarset = tmp_ptr; + int* tmp_ptr2 = (int*)realloc(bddlevel2var,sizeof(int)*(num+1)); + if (__unlikely(tmp_ptr2 == NULL)) { free(bddvarset); return bdd_error(BDD_MEMORY); } - if (__unlikely((bddvar2level = - (int*)realloc(bddvar2level,sizeof(int)*(num+1))) == NULL)) + bddlevel2var = tmp_ptr2; + tmp_ptr2 = (int*)realloc(bddvar2level,sizeof(int)*(num+1)); + if (__unlikely(tmp_ptr2 == NULL)) { free(bddvarset); free(bddlevel2var); return bdd_error(BDD_MEMORY); } + bddvar2level = tmp_ptr2; } if (__likely(bddrefstack != NULL)) diff --git a/buddy/src/reorder.c b/buddy/src/reorder.c index f6cf49982..b368e911c 100644 --- a/buddy/src/reorder.c +++ b/buddy/src/reorder.c @@ -812,7 +812,7 @@ static void addref_rec(int r, char *dep) if (r < 2) return; - if (bddnodes[r].refcou == 0) + if (bddnodes[r].refcou == 0 || MARKED(r)) { bddfreenum--; @@ -880,7 +880,10 @@ static int mark_roots(void) } if ((extroots=(int*)(malloc(sizeof(int)*extrootsize))) == NULL) - return bdd_error(BDD_MEMORY); + { + free(dep); + return bdd_error(BDD_MEMORY); + } iactmtx = imatrixNew(bddvarnum);