[FIX] deadlock in da_manager 86/52286/1
authorAnatolii Nikulin <nikulin.a@samsung.com>
Fri, 20 Nov 2015 10:48:45 +0000 (13:48 +0300)
committerAnatolii Nikulin <nikulin.a@samsung.com>
Fri, 20 Nov 2015 10:58:54 +0000 (13:58 +0300)
Change-Id: If0cf631ef695c1db94762034a5c6e4adb73a6524
Signed-off-by: Anatolii Nikulin <nikulin.a@samsung.com>
daemon/target.c

index 729a6ce..f70200e 100644 (file)
@@ -63,7 +63,7 @@ struct target *target_ctor(void)
        return t;
 }
 
-void target_dtor(struct target *t)
+void target_clean(struct target *t)
 {
        t->allocmem = 0;
        t->event_fd_released = 0;
@@ -76,7 +76,11 @@ void target_dtor(struct target *t)
        if (t->socket != UNKNOWN_FD)
                close(t->socket);
        t->socket = -1;
+}
 
+void target_dtor(struct target *t)
+{
+       target_clean(t);
        thread_dtor(t->thread);
        target_free(t);
 }
@@ -169,11 +173,17 @@ static struct target *target_malloc(void)
                 * and can be released. target_use and event_fd_released are set
                 * in different threads asynchronously
                 */
-               if (target_use[i] == 1 && target_array[i].event_fd_released == 1) {
-                       target_dtor(&target_array[i]);
+               if (target_use[i] == 1 &&
+                   target_array[i].event_fd_released == 1) {
+                       target_clean(&target_array[i]);
+                       thread_dtor(target_array[i].thread);
+                       if (target_use[i] == 0)
+                               LOGE("double free t=%p\n", &target_array[i]);
                        target_use[i] = 0;
                }
+       }
 
+       for (i = 0; i < MAX_TARGET_COUNT; i++) {
                if (target_use[i] == 0) {
                        target_use[i] = 1;
                        t = &target_array[i];