chris - 2008-07-23

Hi all,
I used Rational purify profiler to profile the sphinx3,the purify reported that:
in file src\libs3decoder\libam\ms_mgau.c
function ms_mgau_init(char meanfile,
char
varfile, float64 varfloor,
char mixwfile, float64 mixwfloor,
int32 precomp, char
senmgau, char *lambdafile, int32 _topn)
.
.
.
188 msg->mgau2sen =
189 (mgau2sen_t ) ckd_calloc(g->n_mgau, sizeof(mgau2sen_t ));
190 for (i = 0; i < s->n_sen; i++) {
191 m2s = (mgau2sen_t
) ckd_calloc(1, sizeof(mgau2sen_t));
192 m2s->sen = i;
193 m2s->next = msg->mgau2sen[s->mgau[i]];
194 msg->mgau2sen[s->mgau[i]] = m2s;
195 }
.
.
this part malloc a msg->mgau2sen with type mgau2sen_t
,and msg->mgau2sen points to a link list which is also created by malloc.

BUT in the free function

226 void
227 ms_mgau_free(ms_mgau_model_t * msg)
228 {
229 if (msg == NULL)
230 return;
231
232 gauden_free(msg->g);
233 senone_free(msg->s);
234 ckd_free_3d((void *) msg->dist);
235 ckd_free(msg->mgau_active);
236 ckd_free(msg);
237 }

this function has no code about above init function code which I point,I changed the ms_mgau_free to
ms_mgau_free(ms_mgau_model_t * msg)
{
mgau2sen_t* p;
mgau2sen_t
q ;

if (msg == NULL)
    return;

gauden_free(msg-&gt;g);
senone_free(msg-&gt;s);
ckd_free_3d((void *) msg-&gt;dist);
ckd_free(msg-&gt;mgau_active);

p = msg-&gt;mgau2sen;
q = p[0];
if(q != NULL)
{
mgau2sen_t *k;
while(q != NULL)
{
    k=q-&gt;next;
    ckd_free(q);
    q=k;
}
}
ckd_free(msg-&gt;mgau2sen);

ckd_free(msg)

}

the memory leakage is not reported again.

and In another file src\libs3decoder\libsearch\kb.c:
in function
void
kb_set_uttid(char _uttid, char _uttfile, kb_t * _kb)
{
assert(_kb != NULL);
assert(_uttid != NULL);

ckd_free(_kb-&gt;uttid);
_kb-&gt;uttid = NULL;
_kb-&gt;uttid = ckd_salloc(_uttid);

ckd_free(_kb-&gt;uttfile);
_kb-&gt;uttfile = NULL;
if (_uttfile)
_kb-&gt;uttfile = ckd_salloc(_uttfile);

}

the purify said the _kb->uttid line has memory leakage,then I changed the function kb_free()
I added "ckd_free(kb->uttid);" at bottom of the function,is that the right way?and what about the _uttfile memory?