fix: ust comm error handling segfault
[lttng-ust.git] / liblttng-ust / lttng-ust-comm.c
index b3567dda36f0c14042546f41d62656fcbadf79f0..44e8bab4c24ca4aa2a77b72727288c9b24c8e67d 100644 (file)
@@ -289,28 +289,30 @@ end:
                //lur.ret_code = USTCOMM_SESSION_FAIL;
                lur.ret_code = ret;
        }
-       switch (lum->cmd) {
-       case LTTNG_UST_STREAM:
-               /*
-                * Special-case reply to send stream info.
-                * Use lum.u output.
-                */
-               lur.u.stream.memory_map_size = *args.stream.memory_map_size;
-               shm_fd = *args.stream.shm_fd;
-               wait_fd = *args.stream.wait_fd;
-               break;
-       case LTTNG_UST_METADATA:
-       case LTTNG_UST_CHANNEL:
-               lur.u.channel.memory_map_size = *args.channel.memory_map_size;
-               shm_fd = *args.channel.shm_fd;
-               wait_fd = *args.channel.wait_fd;
-               break;
-       case LTTNG_UST_TRACER_VERSION:
-               lur.u.version = lum->u.version;
-               break;
-       case LTTNG_UST_TRACEPOINT_LIST_GET:
-               memcpy(&lur.u.tracepoint, &lum->u.tracepoint, sizeof(lur.u.tracepoint));
-               break;
+       if (ret >= 0) {
+               switch (lum->cmd) {
+               case LTTNG_UST_STREAM:
+                       /*
+                        * Special-case reply to send stream info.
+                        * Use lum.u output.
+                        */
+                       lur.u.stream.memory_map_size = *args.stream.memory_map_size;
+                       shm_fd = *args.stream.shm_fd;
+                       wait_fd = *args.stream.wait_fd;
+                       break;
+               case LTTNG_UST_METADATA:
+               case LTTNG_UST_CHANNEL:
+                       lur.u.channel.memory_map_size = *args.channel.memory_map_size;
+                       shm_fd = *args.channel.shm_fd;
+                       wait_fd = *args.channel.wait_fd;
+                       break;
+               case LTTNG_UST_TRACER_VERSION:
+                       lur.u.version = lum->u.version;
+                       break;
+               case LTTNG_UST_TRACEPOINT_LIST_GET:
+                       memcpy(&lur.u.tracepoint, &lum->u.tracepoint, sizeof(lur.u.tracepoint));
+                       break;
+               }
        }
        ret = send_reply(sock, &lur);
        if (ret < 0) {
This page took 0.023076 seconds and 4 git commands to generate.