api: fix vlibmemory coverity warning CID-300152
[vpp.git] / src / vlibmemory / socket_api.c
index 106fcb2..c139b65 100644 (file)
@@ -220,6 +220,12 @@ static void
 socket_cleanup_pending_remove_registration_cb (u32 *preg_index)
 {
   vl_api_registration_t *rp = vl_socket_get_registration (*preg_index);
+  if (!rp)
+    {
+      /* Might already have gone */
+      return;
+    }
+
   clib_file_main_t *fm = &file_main;
   u32 pending_remove_file_index = vl_api_registration_file_index (rp);
 
@@ -282,6 +288,10 @@ vl_socket_read_ready (clib_file_t * uf)
     }
 
   rp = vl_socket_get_registration (reg_index);
+  if (!rp)
+    {
+      return 0;
+    }
 
   /* Ignore unprocessed_input for now, n describes input_buffer for now. */
   n = read (uf->file_descriptor, socket_main.input_buffer,
@@ -402,7 +412,7 @@ vl_socket_write_ready (clib_file_t * uf)
   while (remaining_bytes > 0)
     {
       bytes_to_send = remaining_bytes > 4096 ? 4096 : remaining_bytes;
-      n = write (uf->file_descriptor, p, bytes_to_send);
+      n = send (uf->file_descriptor, p, bytes_to_send, MSG_NOSIGNAL);
       if (n < 0)
        {
          if (errno == EAGAIN)
@@ -796,10 +806,18 @@ vl_sock_api_init (vlib_main_t * vm)
     return 0;
 
 #define _(N, n, t)                                                            \
-  vl_msg_api_set_handlers (                                                   \
-    VL_API_##N, #n, vl_api_##n##_t_handler, vl_api_##n##_t_endian,            \
-    vl_api_##n##_t_format, sizeof (vl_api_##n##_t), t, vl_api_##n##_t_tojson, \
-    vl_api_##n##_t_fromjson, vl_api_##n##_t_calc_size);                       \
+  vl_msg_api_config (&(vl_msg_api_msg_config_t){                              \
+    .id = VL_API_##N,                                                         \
+    .name = #n,                                                               \
+    .handler = vl_api_##n##_t_handler,                                        \
+    .endian = vl_api_##n##_t_endian,                                          \
+    .format_fn = vl_api_##n##_t_format,                                       \
+    .size = sizeof (vl_api_##n##_t),                                          \
+    .traced = t,                                                              \
+    .tojson = vl_api_##n##_t_tojson,                                          \
+    .fromjson = vl_api_##n##_t_fromjson,                                      \
+    .calc_size = vl_api_##n##_t_calc_size,                                    \
+  });                                                                         \
   am->msg_data[VL_API_##N].replay_allowed = 0;
   foreach_vlib_api_msg;
 #undef _