From d06fc3abf4f35290882dae4d2d22be6c7cadc46c Mon Sep 17 00:00:00 2001 From: Yongjoo Ahn Date: Mon, 19 Jun 2023 17:06:55 +0900 Subject: [PATCH] [filter] Fix mem leak when set input/output info - Add calls for `gst_tensors_info_free` Signed-off-by: Yongjoo Ahn --- .../tensor_filter/tensor_filter_tensorflow_lite.cc | 19 ++++++++++++------- gst/nnstreamer/tensor_filter/tensor_filter_single.c | 3 +++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.cc b/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.cc index c43e595..3e20f5b 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.cc +++ b/ext/nnstreamer/tensor_filter/tensor_filter_tensorflow_lite.cc @@ -694,6 +694,7 @@ TFLiteInterpreter::setTensorProp ( int TFLiteInterpreter::setInputTensorProp () { + gst_tensors_info_free (&inputTensorMeta); return setTensorProp (interpreter->inputs (), &inputTensorMeta); } @@ -704,6 +705,7 @@ TFLiteInterpreter::setInputTensorProp () int TFLiteInterpreter::setOutputTensorProp () { + gst_tensors_info_free (&outputTensorMeta); return setTensorProp (interpreter->outputs (), &outputTensorMeta); } @@ -1559,25 +1561,25 @@ tflite_setInputDim (const GstTensorFilterProperties *prop, void **private_data, /** get current input tensor info for resetting */ status = core->getInputTensorDim (&cur_in_info); if (status != 0) - return status; + goto exit; /** set new input tensor info */ status = core->setInputTensorDim (in_info); if (status != 0) { tflite_setInputDim_recovery (core, &cur_in_info, "while setting input tensor info", 0); - return status; + goto exit; } /** update input tensor info */ if ((status = core->setInputTensorProp ()) != 0) { tflite_setInputDim_recovery (core, &cur_in_info, "while updating input tensor info", 1); - return status; + goto exit; } /** update output tensor info */ if ((status = core->setOutputTensorProp ()) != 0) { tflite_setInputDim_recovery (core, &cur_in_info, "while updating output tensor info", 2); - return status; + goto exit; } /** update the input and output tensor cache */ @@ -1585,7 +1587,7 @@ tflite_setInputDim (const GstTensorFilterProperties *prop, void **private_data, if (status != 0) { tflite_setInputDim_recovery ( core, &cur_in_info, "while updating input and output tensor cache", 2); - return status; + goto exit; } /** get output tensor info to be returned */ @@ -1593,10 +1595,13 @@ tflite_setInputDim (const GstTensorFilterProperties *prop, void **private_data, if (status != 0) { tflite_setInputDim_recovery ( core, &cur_in_info, "while retreiving update output tensor info", 2); - return status; + goto exit; } - return 0; +exit: + gst_tensors_info_free (&cur_in_info); + + return status; } /** diff --git a/gst/nnstreamer/tensor_filter/tensor_filter_single.c b/gst/nnstreamer/tensor_filter/tensor_filter_single.c index 9a8f36a..f5363e1 100644 --- a/gst/nnstreamer/tensor_filter/tensor_filter_single.c +++ b/gst/nnstreamer/tensor_filter/tensor_filter_single.c @@ -424,6 +424,9 @@ g_tensor_filter_set_input_info (GTensorFilterSingle * self, } if (status == 0) { + gst_tensors_info_free (&priv->prop.input_meta); + gst_tensors_info_free (&priv->prop.output_meta); + gst_tensors_info_copy (&priv->prop.input_meta, in_info); gst_tensors_info_copy (&priv->prop.output_meta, out_info); } -- 2.7.4