DbusIpcModule: added checks before calling dbus_watch_handle
authorTimo Lotterbach <timo.lotterbach@bmw-carit.de>
Thu, 25 Oct 2012 12:12:43 +0000 (05:12 -0700)
committerMichael Schuldt <michael.schuldt@bmw.de>
Fri, 26 Oct 2012 06:14:02 +0000 (09:14 +0300)
LayerManagerPlugins/IpcModules/DbusIpcModule/src/message.c

index 813249e..5e03465 100644 (file)
@@ -313,13 +313,20 @@ void handleWatchesForFds(fd_set in, fd_set out)
         {
             DBusWatch* activeWatch = gDbus.incomingWatch[fd];
 
-            pthread_mutex_lock(&gDbus.mutex);
-            dbus_bool_t success = dbus_watch_handle(activeWatch, DBUS_WATCH_READABLE);
-            pthread_mutex_unlock(&gDbus.mutex);
-
-            if (!success)
+            if (activeWatch)
+            {
+                pthread_mutex_lock(&gDbus.mutex);
+                dbus_bool_t success = dbus_watch_handle(activeWatch, DBUS_WATCH_READABLE);
+                pthread_mutex_unlock(&gDbus.mutex);
+
+                if (!success)
+                {
+                    printf("incoming dbus_watch_handle() failed\n");
+                }
+            }
+            else
             {
-                printf("incoming dbus_watch_handle() failed\n");
+                printf("no watch was found for incoming fd %d, not calling dbus_watch_handle(NULL)\n", fd);
             }
         }
     }
@@ -330,13 +337,20 @@ void handleWatchesForFds(fd_set in, fd_set out)
         {
             DBusWatch* activeWatch = gDbus.outgoingWatch[fd];
 
-            pthread_mutex_lock(&gDbus.mutex);
-            dbus_bool_t success = dbus_watch_handle(activeWatch, DBUS_WATCH_WRITABLE);
-            pthread_mutex_unlock(&gDbus.mutex);
-
-            if (!success)
+            if (activeWatch)
+            {
+                pthread_mutex_lock(&gDbus.mutex);
+                dbus_bool_t success = dbus_watch_handle(activeWatch, DBUS_WATCH_WRITABLE);
+                pthread_mutex_unlock(&gDbus.mutex);
+
+                if (!success)
+                {
+                    printf("outgoing dbus_watch_handle() failed\n");
+                }
+            }
+            else
             {
-                printf("outgoing dbus_watch_handle() failed\n");
+                printf("no watch was found for outgoing fd %d, not calling dbus_watch_handle(NULL)\n", fd);
             }
         }
     }