aboutsummaryrefslogtreecommitdiff
path: root/src/rps/rps-sampler_common.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-10-15 23:11:31 +0200
committerJulius Bünger <buenger@mytum.de>2018-10-15 23:11:31 +0200
commit564df39557f1a69280f36ff5173807856ff41067 (patch)
tree6989e798d823022db14983c92ffde581a19590b6 /src/rps/rps-sampler_common.c
parent1ca9b7ee09328a33f5f428ee3c37acc8479e31fa (diff)
downloadgnunet-564df39557f1a69280f36ff5173807856ff41067.tar.gz
gnunet-564df39557f1a69280f36ff5173807856ff41067.zip
RPS: Cleanup datastructures, NULL out freed pointers
Diffstat (limited to 'src/rps/rps-sampler_common.c')
-rw-r--r--src/rps/rps-sampler_common.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/rps/rps-sampler_common.c b/src/rps/rps-sampler_common.c
index d004c06a5..5dbb5315a 100644
--- a/src/rps/rps-sampler_common.c
+++ b/src/rps/rps-sampler_common.c
@@ -387,6 +387,10 @@ check_n_peers_ready (void *cls,
387{ 387{
388 struct RPS_SamplerRequestHandle *req_handle = cls; 388 struct RPS_SamplerRequestHandle *req_handle = cls;
389 (void) id; 389 (void) id;
390 RPS_sampler_n_rand_peers_ready_cb tmp_cb;
391 struct GNUNET_PeerIdentity *peers;
392 uint32_t num_peers;
393 void *cb_cls;
390 394
391 req_handle->cur_num_peers++; 395 req_handle->cur_num_peers++;
392 LOG (GNUNET_ERROR_TYPE_DEBUG, 396 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -400,9 +404,20 @@ check_n_peers_ready (void *cls,
400 LOG (GNUNET_ERROR_TYPE_DEBUG, 404 LOG (GNUNET_ERROR_TYPE_DEBUG,
401 "returning %" PRIX32 " peers to the client\n", 405 "returning %" PRIX32 " peers to the client\n",
402 req_handle->num_peers); 406 req_handle->num_peers);
403 req_handle->callback (req_handle->ids, req_handle->num_peers, req_handle->cls);
404 407
408 /* Copy pointers and peers temporarily as they
409 * might be deleted from within the callback */
410 tmp_cb = req_handle->callback;
411 num_peers = req_handle->num_peers;
412 peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity);
413 GNUNET_memcpy (peers,
414 req_handle->ids,
415 num_peers * sizeof (struct GNUNET_PeerIdentity));
416 cb_cls = req_handle->cls;
405 RPS_sampler_request_cancel (req_handle); 417 RPS_sampler_request_cancel (req_handle);
418 req_handle = NULL;
419 tmp_cb (peers, num_peers, cb_cls);
420 GNUNET_free (peers);
406 } 421 }
407} 422}
408 423
@@ -493,10 +508,12 @@ RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle)
493 req_handle->sampler->notify_ctx_tail, 508 req_handle->sampler->notify_ctx_tail,
494 i->notify_ctx); 509 i->notify_ctx);
495 GNUNET_free (i->notify_ctx); 510 GNUNET_free (i->notify_ctx);
511 i->notify_ctx = NULL;
496 } 512 }
497 GNUNET_free (i); 513 GNUNET_free (i);
498 } 514 }
499 GNUNET_free (req_handle->ids); 515 GNUNET_free (req_handle->ids);
516 req_handle->ids = NULL;
500 GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head, 517 GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head,
501 req_handle->sampler->req_handle_tail, 518 req_handle->sampler->req_handle_tail,
502 req_handle); 519 req_handle);