#include #include #include #include #include #include #include int main(int argc, char** argv) { DBusError err; dbus_error_init(&err); DBusConnection *conn = dbus_bus_get(DBUS_BUS_SESSION, &err); if (NULL == conn) exit(1); dbus_bus_add_match(conn, "sender='test.server'", &err); dbus_connection_flush(conn); if (dbus_error_is_set(&err)) exit(1); while (true) { dbus_connection_read_write(conn, 0); DBusMessage *msg = dbus_connection_pop_message(conn); if (NULL == msg) { sleep(1); continue; } if (dbus_message_is_signal(msg, "test.server.Event", "Broadcast")) { dbus_error_init(&err); char **array = NULL; char **array2 = NULL; int len; int len2; int fd = -1; int fd2 = -1; int nu = -1; int ret; struct stat st; /* !!!! we try to read three arguments while the message contains only two !!! */ /* if (!dbus_message_get_args(msg, &err, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &len, DBUS_TYPE_UNIX_FD, &fd, DBUS_TYPE_INVALID)) { */ if (!dbus_message_get_args(msg, &err, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, &len, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array2, &len2, DBUS_TYPE_UNIX_FD, &fd, DBUS_TYPE_UNIX_FD, &fd2, DBUS_TYPE_INT32, &nu, DBUS_TYPE_INVALID)) { fprintf(stderr, "Message parsing error: %s\n", err.message); if ((ret = fstat(fd, &st)) == -1) { printf("unix fd isn't leak\n"); } else if (ret == 0) printf("unix fd (%d) leak\n", fd); if ((ret = fstat(fd2, &st)) == -1) { printf("unix fd isn't leak\n"); } else if (ret == 0) printf("unix fd (%d) leak\n", fd2); if (array) { printf("array of string leak\n"); int i = 0; while (i < len) { printf("%s\n", array[i]); i++; } } if (array2) { printf("array of string leak\n"); int i = 0; while (i < len2) { printf("%s\n", array2[i]); i++; } } } } dbus_message_unref(msg); } return 0; }