Skip to content

Commit 1e3f6e5

Browse files
committed
[CodeClean] handle error case
Fix svace issue, check param and remove unreached code when an error occurs. Signed-off-by: Jaeyun Jung <[email protected]>
1 parent 70252a3 commit 1e3f6e5

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

daemon/mlops-agent-node.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ mlops_node_create (const gchar * name, const mlops_node_type_e type,
153153
GError *err = NULL;
154154
GstStateChangeReturn ret;
155155

156+
g_return_val_if_fail (id != NULL, -EINVAL);
157+
156158
switch (type) {
157159
case MLOPS_NODE_TYPE_PIPELINE:
158160
{
@@ -173,9 +175,6 @@ mlops_node_create (const gchar * name, const mlops_node_type_e type,
173175
desc, (err) ? err->message : "unknown reason");
174176
g_clear_error (&err);
175177

176-
if (pipeline)
177-
gst_object_unref (pipeline);
178-
179178
result = -ESTRPIPE;
180179
goto error;
181180
}
@@ -186,12 +185,11 @@ mlops_node_create (const gchar * name, const mlops_node_type_e type,
186185
ml_loge
187186
("Failed to set the state of the pipeline to PAUSED. For the detail, please check the GStreamer log message.");
188187

189-
gst_object_unref (pipeline);
190188
result = -ESTRPIPE;
191189
goto error;
192190
}
193191

194-
/* Add node info into hash table. */
192+
/* Final step, add node info into hash table. */
195193
node = g_new0 (mlops_node_s, 1);
196194
node->type = type;
197195
node->id = g_get_monotonic_time ();
@@ -204,12 +202,12 @@ mlops_node_create (const gchar * name, const mlops_node_type_e type,
204202
g_hash_table_insert (g_mlops_node_table, GINT_TO_POINTER (node->id), node);
205203
G_UNLOCK (mlops_node_table);
206204

205+
*id = node->id;
206+
207207
error:
208-
if (result == 0) {
209-
*id = node->id;
210-
} else {
211-
if (node)
212-
_mlops_node_free (node);
208+
if (result != 0) {
209+
if (pipeline)
210+
gst_object_unref (pipeline);
213211
}
214212

215213
g_free (desc);

0 commit comments

Comments
 (0)