Skip to content

Commit 466a210

Browse files
Jyri Sarhalgirdwood
authored andcommitted
modules: tensorflow: Fix memory leaks from failed initialization
Fix memory leaks from failed initialization. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent b617c0f commit 466a210

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/audio/tensorflow/tflm-classify.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ __cold static int tflm_init(struct processing_module *mod)
7171
if (!cd->model_handler) {
7272
comp_err(dev, "mod_data_blob_handler_new() failed.");
7373
ret = -ENOMEM;
74-
goto cd_fail;
74+
goto fail;
7575
}
7676

7777
/* Get configuration data and reset DRC state */
7878
ret = comp_init_data_blob(cd->model_handler, bs, cfg->data);
7979
if (ret < 0) {
8080
comp_err(dev, "comp_init_data_blob() failed.");
81-
goto cd_fail;
81+
goto fail;
8282
}
8383

8484
/* hard coded atm */
@@ -88,19 +88,21 @@ __cold static int tflm_init(struct processing_module *mod)
8888
ret = TF_SetModel(&cd->tfc, NULL);
8989
if (!ret) {
9090
comp_err(dev, "failed to set model");
91-
return ret;
91+
goto fail;
9292
}
9393

9494
/* initialise ops */
9595
ret = TF_InitOps(&cd->tfc);
9696
if (!ret) {
9797
comp_err(dev, "failed to init ops");
98-
return ret;
98+
goto fail;
9999
}
100100

101101
return ret;
102102

103-
cd_fail:
103+
fail:
104+
/* Passing NULL pointer to free functions is Ok */
105+
mod_data_blob_handler_free(mod, cd->model_handler);
104106
mod_free(mod, cd);
105107
return ret;
106108
}

0 commit comments

Comments
 (0)