OSDN Git Service

android: Fix NULL pointer dereference
authorMarcin Kraglak <marcin.kraglak@tieto.com>
Mon, 31 Mar 2014 12:45:13 +0000 (14:45 +0200)
committerSzymon Janc <szymon.janc@tieto.com>
Mon, 31 Mar 2014 13:53:31 +0000 (15:53 +0200)
If there is no adapter, hal_ipc in not initialized. Below is
message from valgrind:

==22501== Invalid read of size 4
==22501==    at 0x805B809: ipc_unregister (ipc.c:421)
==22501==    by 0x804AEAF: main (main.c:548)
==22501==  Address 0x4 is not stack'd, malloc'd or (recently) free'd

android/main.c

index 828f81d..e229a6d 100644 (file)
@@ -541,8 +541,11 @@ int main(int argc, char *argv[])
        bt_bluetooth_cleanup();
        g_main_loop_unref(event_loop);
 
-       ipc_unregister(hal_ipc, HAL_SERVICE_ID_CORE);
-       ipc_cleanup(hal_ipc);
+       /* If no adapter was initialized, hal_ipc is NULL */
+       if (hal_ipc) {
+               ipc_unregister(hal_ipc, HAL_SERVICE_ID_CORE);
+               ipc_cleanup(hal_ipc);
+       }
 
        info("Exit");