Fix: ust-app null pointer check needed for main refactoring
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index 9dbd49bc3fe5a2911e0516324824383f9257908a..bc1d62dc7862c342bbc2cbd08d1d83cc88d59cbb 100644 (file)
@@ -1875,6 +1875,7 @@ static int create_ust_app_session(struct ltt_ust_session *usess,
                /* Init local registry. */
                ret = setup_buffer_reg_pid(ua_sess, app, NULL);
                if (ret < 0) {
+                       delete_ust_app_session(-1, ua_sess, app);
                        goto error;
                }
                break;
@@ -1882,6 +1883,7 @@ static int create_ust_app_session(struct ltt_ust_session *usess,
                /* Look for a global registry. If none exists, create one. */
                ret = setup_buffer_reg_uid(usess, app, NULL);
                if (ret < 0) {
+                       delete_ust_app_session(-1, ua_sess, app);
                        goto error;
                }
                break;
@@ -3406,41 +3408,63 @@ void ust_app_clean_list(void)
 
        rcu_read_lock();
 
-       cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
-               ret = lttng_ht_del(ust_app_ht, &iter);
-               assert(!ret);
-               call_rcu(&app->pid_n.head, delete_ust_app_rcu);
+       if (ust_app_ht) {
+               cds_lfht_for_each_entry(ust_app_ht->ht, &iter.iter, app, pid_n.node) {
+                       ret = lttng_ht_del(ust_app_ht, &iter);
+                       assert(!ret);
+                       call_rcu(&app->pid_n.head, delete_ust_app_rcu);
+               }
        }
 
        /* Cleanup socket hash table */
-       cds_lfht_for_each_entry(ust_app_ht_by_sock->ht, &iter.iter, app,
-                       sock_n.node) {
-               ret = lttng_ht_del(ust_app_ht_by_sock, &iter);
-               assert(!ret);
+       if (ust_app_ht_by_sock) {
+               cds_lfht_for_each_entry(ust_app_ht_by_sock->ht, &iter.iter, app,
+                               sock_n.node) {
+                       ret = lttng_ht_del(ust_app_ht_by_sock, &iter);
+                       assert(!ret);
+               }
        }
 
        /* Cleanup notify socket hash table */
-       cds_lfht_for_each_entry(ust_app_ht_by_notify_sock->ht, &iter.iter, app,
-                       notify_sock_n.node) {
-               ret = lttng_ht_del(ust_app_ht_by_notify_sock, &iter);
-               assert(!ret);
+       if (ust_app_ht_by_notify_sock) {
+               cds_lfht_for_each_entry(ust_app_ht_by_notify_sock->ht, &iter.iter, app,
+                               notify_sock_n.node) {
+                       ret = lttng_ht_del(ust_app_ht_by_notify_sock, &iter);
+                       assert(!ret);
+               }
        }
        rcu_read_unlock();
 
        /* Destroy is done only when the ht is empty */
-       ht_cleanup_push(ust_app_ht);
-       ht_cleanup_push(ust_app_ht_by_sock);
-       ht_cleanup_push(ust_app_ht_by_notify_sock);
+       if (ust_app_ht) {
+               ht_cleanup_push(ust_app_ht);
+       }
+       if (ust_app_ht_by_sock) {
+               ht_cleanup_push(ust_app_ht_by_sock);
+       }
+       if (ust_app_ht_by_notify_sock) {
+               ht_cleanup_push(ust_app_ht_by_notify_sock);
+       }
 }
 
 /*
  * Init UST app hash table.
  */
-void ust_app_ht_alloc(void)
+int ust_app_ht_alloc(void)
 {
        ust_app_ht = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
+       if (!ust_app_ht) {
+               return -1;
+       }
        ust_app_ht_by_sock = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
+       if (!ust_app_ht_by_sock) {
+               return -1;
+       }
        ust_app_ht_by_notify_sock = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG);
+       if (!ust_app_ht_by_notify_sock) {
+               return -1;
+       }
+       return 0;
 }
 
 /*
This page took 0.024569 seconds and 4 git commands to generate.