From e9cb00442dfc2a6dd7910e4c361a37cf3f523128 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Fri, 15 Nov 2013 15:11:37 +0000 Subject: [PATCH] - dont use a cancel handle if cont is NULL, fix potential memleak --- src/mesh/gnunet-service-mesh_connection.c | 21 ++++++++++++++++++++- src/mesh/gnunet-service-mesh_connection.h | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index e76839596..499c75525 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -216,8 +216,19 @@ struct MeshConnection */ struct MeshConnectionQueue { + /** + * Peer queue handle, to cancel if necessary. + */ struct MeshPeerQueue *q; + + /** + * Continuation to call once sent. + */ GMC_sent cont; + + /** + * Closure for @c cont. + */ void *cont_cls; }; @@ -2389,7 +2400,8 @@ GMC_is_sendable (struct MeshConnection *c, int fwd) * @param cont Continuation called once message is sent. Can be NULL. * @param cont_cls Closure for @c cont. * - * @return Handle to cancel the message before it's sent. NULL on error. + * @return Handle to cancel the message before it's sent. + * NULL on error or if @c cont is NULL. * Invalid on @c cont call. */ struct MeshConnectionQueue * @@ -2505,6 +2517,13 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, LOG (GNUNET_ERROR_TYPE_DEBUG, " C_P+ %p %u\n", c, c->pending_messages); c->pending_messages++; + if (NULL == cont) + { + (void) GMP_queue_add (get_hop (c, fwd), data, type, size, c, fwd, + &message_sent, q); + return NULL; + } + q = GNUNET_new (struct MeshConnectionQueue); q->q = GMP_queue_add (get_hop (c, fwd), data, type, size, c, fwd, &message_sent, q); diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h index d35630ef6..6faf594af 100644 --- a/src/mesh/gnunet-service-mesh_connection.h +++ b/src/mesh/gnunet-service-mesh_connection.h @@ -454,7 +454,8 @@ GMC_cancel (struct MeshConnectionQueue *q); * @param cont Continuation called once message is sent. Can be NULL. * @param cont_cls Closure for @c cont. * - * @return Handle to cancel the message before it's sent. NULL on error. + * @return Handle to cancel the message before it's sent. + * NULL on error or if @c cont is NULL. * Invalid on @c cont call. */ struct MeshConnectionQueue * -- 2.25.1