Thread (2 messages) 2 messages, 2 authors, 2010-12-14
STALE5706d

[PATCH] Error should be returned instead of unnecessary dict_append_array()

From: Pawel Wieczorkiewicz <hidden>
Date: 2010-12-14 14:20:27
Subsystem: the rest · Maintainer: Linus Torvalds

If there are no adapter up and running, there would be
no elements to be added using dict_append_array(). We
should return DBus error ".DoesNotExist", rather than
appending NULL pointer and zero elements.

On behalf of ST-Ericsson SA
---
 src/manager.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/manager.c b/src/manager.c
index c8ec7e5..9060180 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -185,12 +185,21 @@ static DBusMessage *get_properties(DBusConnection *conn,
 		array[i] = (char *) adapter_get_path(adapter);
 		i++;
 	}
+
+	if (!i)
+		goto error;
+
 	dict_append_array(&dict, "Adapters", DBUS_TYPE_OBJECT_PATH, &array, i);
 	g_free(array);
 
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
+
+error:
+	g_free(array);
+	g_free(reply);
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".DoesNotExist", "Adapter does not exist");
 }
 
 static GDBusMethodTable manager_methods[] = {
-- 
1.7.0.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help