Fix: statedump: invalid read during iter_end
[lttng-ust.git] / liblttng-ust / lttng-ust-statedump.c
index efa8a55aa675771c50ac57031c985f1787c70e21..606a800e3e6be49b8312a7a85752922038adb580 100644 (file)
@@ -35,6 +35,7 @@
 #include "lttng-ust-statedump.h"
 #include "jhash.h"
 #include "getenv.h"
+#include "compat.h"
 
 #define TRACEPOINT_DEFINE
 #include "ust_lib.h"                           /* Only define. */
@@ -246,6 +247,13 @@ void trace_debug_link_cb(struct lttng_session *session, void *priv)
                bin_data->dbg_file, bin_data->crc);
 }
 
+static
+void procname_cb(struct lttng_session *session, void *priv)
+{
+       char *procname = (char *) priv;
+       tracepoint(lttng_ust_statedump, procname, session, procname);
+}
+
 static
 void trace_start_cb(struct lttng_session *session, void *priv)
 {
@@ -414,6 +422,8 @@ void iter_end(struct dl_iterate_data *data, void *ip)
 {
        unsigned int i;
 
+       if (data->cancel)
+               goto end;
        /*
         * Iterate on hash table.
         * For each marked, traced, do nothing.
@@ -423,10 +433,10 @@ void iter_end(struct dl_iterate_data *data, void *ip)
         */
        for (i = 0; i < UST_DL_STATE_TABLE_SIZE; i++) {
                struct cds_hlist_head *head;
-               struct lttng_ust_dl_node *e;
+               struct lttng_ust_dl_node *e, *tmp;
 
                head = &dl_state_table[i];
-               cds_hlist_for_each_entry_2(e, head, node) {
+               cds_hlist_for_each_entry_safe_2(e, tmp, head, node) {
                        if (e->marked) {
                                if (!e->traced) {
                                        trace_lib_load(&e->bin_data, ip);
@@ -441,6 +451,7 @@ void iter_end(struct dl_iterate_data *data, void *ip)
                        }
                }
        }
+end:
        ust_unlock();
 }
 
@@ -590,6 +601,16 @@ int do_baddr_statedump(void *owner)
        return 0;
 }
 
+static
+int do_procname_statedump(void *owner)
+{
+       if (lttng_getenv("LTTNG_UST_WITHOUT_PROCNAME_STATEDUMP"))
+               return 0;
+
+       trace_statedump_event(procname_cb, owner, lttng_ust_sockinfo_get_procname(owner));
+       return 0;
+}
+
 /*
  * Generate a statedump of a given traced application. A statedump is
  * delimited by start and end events. For a given (process, session)
@@ -608,6 +629,7 @@ int do_lttng_ust_statedump(void *owner)
        trace_statedump_start(owner);
        ust_unlock();
 
+       do_procname_statedump(owner);
        do_baddr_statedump(owner);
 
        ust_lock_nocheck();
This page took 0.024719 seconds and 4 git commands to generate.