prevent crash on exit
authorChristian Grothoff <christian@grothoff.org>
Tue, 21 Feb 2017 09:41:53 +0000 (10:41 +0100)
committerChristian Grothoff <christian@grothoff.org>
Tue, 21 Feb 2017 09:41:53 +0000 (10:41 +0100)
src/cadet/cadet_api_new.c
src/util/service_new.c

index 7ed681a9d17630297bd32d9c81a747b0f9205755..100c02a694573453a37ad40c948f21b1c3da210a 100644 (file)
@@ -1244,7 +1244,7 @@ GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p)
                  GNUNET_CONTAINER_multihashmap_remove (p->cadet->ports,
                                                        &p->id,
                                                        p));
-  GNUNET_free (p->handlers);
+  GNUNET_free_non_null (p->handlers);
   GNUNET_free (p);
 }
 
index 8d654c0cbda81591f9edcac1255636520f5df0d7..1b3254cca1d1f3e884060e81ffcff03700746f42 100644 (file)
@@ -1624,17 +1624,7 @@ GNUNET_SERVICE_starT (const char *service_name,
   sh->connect_cb = connect_cb;
   sh->disconnect_cb = disconnect_cb;
   sh->cb_cls = cls;
-  if (NULL != handlers)
-  {
-    unsigned int i;
-
-    for (i=0;NULL != handlers[i].cb; i++) ;
-    sh->handlers = GNUNET_new_array (i + 1,
-                                    struct GNUNET_MQ_MessageHandler);
-    GNUNET_memcpy (sh->handlers,
-                   handlers,
-                   i * sizeof (struct GNUNET_MQ_MessageHandler));
-  }
+  sh->handlers = GNUNET_MQ_copy_handlers (handlers);
   if (GNUNET_OK != setup_service (sh))
   {
     GNUNET_free (sh->handlers);
@@ -1660,7 +1650,7 @@ GNUNET_SERVICE_stoP (struct GNUNET_SERVICE_Handle *srv)
   while (NULL != (client = srv->clients_head))
     GNUNET_SERVICE_client_drop (client);
   teardown_service (srv);
-  GNUNET_free (srv->handlers);
+  GNUNET_free_non_null (srv->handlers);
   GNUNET_free (srv);
 }
 
@@ -1762,17 +1752,7 @@ GNUNET_SERVICE_ruN_ (int argc,
   sh.connect_cb = connect_cb;
   sh.disconnect_cb = disconnect_cb;
   sh.cb_cls = cls;
-  if (NULL != handlers)
-  {
-    unsigned int i;
-
-    for (i=0;NULL != handlers[i].cb; i++) ;
-    sh.handlers = GNUNET_new_array (i + 1,
-                                    struct GNUNET_MQ_MessageHandler);
-    GNUNET_memcpy (sh.handlers,
-                   handlers,
-                   i * sizeof (struct GNUNET_MQ_MessageHandler));
-  }
+  sh.handlers = GNUNET_MQ_copy_handlers (handlers);
   sh.service_name = service_name;
 
   /* setup subsystems */
@@ -1903,7 +1883,7 @@ shutdown:
   }
 #endif
   teardown_service (&sh);
-  GNUNET_free (sh.handlers);
+  GNUNET_free_non_null (sh.handlers);
   GNUNET_SPEEDUP_stop_ ();
   GNUNET_CONFIGURATION_destroy (cfg);
   GNUNET_free_non_null (logfile);