[Subplugin] handle error case
authorJaeyun <jy1210.jung@samsung.com>
Thu, 2 May 2019 11:29:20 +0000 (20:29 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 8 May 2019 08:14:02 +0000 (17:14 +0900)
update code to handle error case of invalid params.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
gst/nnstreamer/nnstreamer_subplugin.c

index 2a4c3d9..51056d7 100644 (file)
@@ -60,6 +60,8 @@ get_subplugin (subpluginType type, const char *name)
   subpluginData *data;
   void *handle;
 
+  g_return_val_if_fail (name, NULL);
+
   G_LOCK (splock);
 
   if (subplugins[type] == NULL)
@@ -115,9 +117,24 @@ gboolean
 register_subplugin (subpluginType type, const char *name, const void *data)
 {
   /** @todo data out of scope at add */
-  subpluginData *spdata = g_new (subpluginData, 1);
+  subpluginData *spdata;
   gboolean ret;
 
+  g_return_val_if_fail (name, FALSE);
+  g_return_val_if_fail (data, FALSE);
+
+  switch (type) {
+    case NNS_SUBPLUGIN_FILTER:
+    case NNS_SUBPLUGIN_DECODER:
+      break;
+    default:
+      /* unknown sub-plugin type */
+      return FALSE;
+  }
+
+  spdata = g_new (subpluginData, 1);
+  g_assert (spdata);
+
   spdata->name = g_strdup (name);
   spdata->data = data;
   spdata->handle = NULL;
@@ -139,8 +156,9 @@ gboolean
 unregister_subplugin (subpluginType type, const char *name)
 {
   gboolean ret;
-  if (subplugins[type] == NULL)
-    return FALSE;
+
+  g_return_val_if_fail (name, FALSE);
+  g_return_val_if_fail (subplugins[type], FALSE);
 
   G_LOCK (splock);
   ret = g_hash_table_remove (subplugins[type], name);