[mlagent] Let `mlagent_get_model_path_from` returns uri in fallback
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Fri, 5 Jan 2024 09:17:27 +0000 (18:17 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 10 Jan 2024 06:27:13 +0000 (15:27 +0900)
- Let the function returns properly allocated gchar* in fallback case.
- Fix memleak (g_strfreev).
- Fix memleak in a testcase.

Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
gst/nnstreamer/ml_agent.c
tests/unittest_mlagent/unittest_mlagent.cc

index f95a049..d5567ff 100644 (file)
@@ -146,6 +146,8 @@ mlagent_get_model_path_from (const GValue * val)
               "Invalid value for the key, %s", JSON_KEY_MODEL_PATH);
           goto fallback;
         }
+
+        g_strfreev (parts);
         return g_strdup (path);
       }
     }
@@ -155,5 +157,5 @@ fallback:
   g_clear_error (&err);
   g_strfreev (parts);
 
-  return uri;
+  return g_strdup (uri);
 }
index 5a0b8d7..1f55a76 100644 (file)
@@ -127,6 +127,8 @@ TEST (testMLAgent, GetModelInvalidModel_n)
    * the given URI as it is so that it is handled by the fallback procedure (i.e., regarding it as a file path).
    */
   EXPECT_STREQ (uri, path);
+
+  g_value_reset (&val);
 }
 
 /**