Skip to content

Commit

Permalink
Fix memory problem caused by wrong array size; destin->maxNs must be …
Browse files Browse the repository at this point in the history
…greater then or equal to nodes->ns
  • Loading branch information
jswiergo committed Sep 21, 2013
1 parent 361032b commit 80a4b8f
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions Destin/DavisDestin/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,18 @@ Destin * InitDestin( uint ni, uint nl, uint *nb, uint nc, float beta, float lamb

ni = (l == 0 ? ni : 4*nb[l-1]);

if( ni + nb[l] + np > maxNs )
{
maxNs = ni + nb[l] + np;
}

float * sharedCentroids;

// calculate the state dimensionality (number of inputs + number of beliefs)
// 2013.4.17
// CZT
uint ns = nb[l] + np + nc + (( l == 0) ? ni*extRatio : ni);

if (ns > maxNs)
{
maxNs = ns;
}

if(isUniform){
MALLOC(d->uf_avgDelta[l], float, ns*nb[l]);
MALLOC(sharedCentroids, float, ns*nb[l]);
Expand Down Expand Up @@ -566,18 +566,18 @@ void addCentroid(Destin * d, uint ni, uint nl, uint *nb, uint nc, float beta, fl

ni = (l == 0 ? ni : 4*nb[l-1]);

if( ni + nb[l] + np > maxNs )
{
maxNs = ni + nb[l] + np;
}

float * sharedCentroids;

// calculate the state dimensionality (number of inputs + number of beliefs)
// 2013.4.17
// CZT
uint ns = nb[l] + np + nc + ((l == 0) ? ni*extRatio : ni);

if (ns > maxNs)
{
maxNs = ns;
}

if(isUniform){
MALLOC(d->uf_avgDelta[l], float, ns*nb[l]);
MALLOC(sharedCentroids, float, ns*nb[l]);
Expand Down Expand Up @@ -1049,11 +1049,6 @@ void killCentroid(Destin * d, uint ni, uint nl, uint *nb, uint nc, float beta, f

ni = (l == 0 ? ni : 4*nb[l-1]);

if( ni + nb[l] + np > maxNs )
{
maxNs = ni + nb[l] + np;
}

float * sharedCentroids;

// calculate the state dimensionality (number of inputs + number of beliefs)
Expand All @@ -1062,6 +1057,12 @@ void killCentroid(Destin * d, uint ni, uint nl, uint *nb, uint nc, float beta, f
// CZT
//
uint ns = (l == 0 ? ni*extRatio+nb[l]+np+nc : ni+nb[l]+np+nc);

if (ns > maxNs)
{
maxNs = ns;
}

if(isUniform){
MALLOC(d->uf_avgDelta[l], float, ns*nb[l]);
MALLOC(sharedCentroids, float, ns*nb[l]);
Expand Down

0 comments on commit 80a4b8f

Please sign in to comment.