Skip to content

Commit 5f5b5e3

Browse files
committed
fix: refcount lmath in fsg to fix memory leak in jsgf2fsg
1 parent 5436249 commit 5f5b5e3

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

programs/pocketsphinx_jsgf2fsg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ get_fsg(jsgf_t *grammar, const char *name)
127127

128128
lmath = logmath_init(1.0001, 0, 0);
129129
fsg = jsgf_build_fsg_raw(grammar, rule, lmath, 1.0);
130+
logmath_free(lmath);
130131
return fsg;
131132
}
132133

@@ -196,6 +197,7 @@ main(int argc, char *argv[])
196197
}
197198
fsg_model_free(fsg);
198199
jsgf_grammar_free(jsgf);
200+
ps_config_free(config);
199201

200202
return 0;
201203
}

src/lm/fsg_model.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include <pocketsphinx.h>
4040

41+
#include "pocketsphinx/logmath.h"
4142
#include "util/pio.h"
4243
#include "util/ckd_alloc.h"
4344
#include "util/strfuncs.h"
@@ -502,7 +503,7 @@ fsg_model_init(char const *name, logmath_t * lmath, float32 lw,
502503
fsg = ckd_calloc(1, sizeof(*fsg));
503504
fsg->refcount = 1;
504505
fsg->link_alloc = listelem_alloc_init(sizeof(fsg_link_t));
505-
fsg->lmath = lmath;
506+
fsg->lmath = logmath_retain(lmath);
506507
fsg->name = name ? ckd_salloc(name) : NULL;
507508
fsg->n_state = n_state;
508509
fsg->lw = lw;
@@ -782,6 +783,7 @@ fsg_model_free(fsg_model_t * fsg)
782783
listelem_alloc_free(fsg->link_alloc);
783784
bitvec_free(fsg->silwords);
784785
bitvec_free(fsg->altwords);
786+
logmath_free(fsg->lmath);
785787
ckd_free(fsg->name);
786788
ckd_free(fsg);
787789
return 0;

0 commit comments

Comments
 (0)