diff options
author | Julius Bünger <buenger@mytum.de> | 2018-10-15 23:11:31 +0200 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-10-15 23:11:31 +0200 |
commit | 564df39557f1a69280f36ff5173807856ff41067 (patch) | |
tree | 6989e798d823022db14983c92ffde581a19590b6 /src/rps | |
parent | 1ca9b7ee09328a33f5f428ee3c37acc8479e31fa (diff) | |
download | gnunet-564df39557f1a69280f36ff5173807856ff41067.tar.gz gnunet-564df39557f1a69280f36ff5173807856ff41067.zip |
RPS: Cleanup datastructures, NULL out freed pointers
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/rps-sampler_common.c | 19 | ||||
-rw-r--r-- | src/rps/rps_api.c | 32 | ||||
-rw-r--r-- | src/rps/test_rps.conf | 2 |
3 files changed, 36 insertions, 17 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); |
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 02d833506..bce567678 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c | |||
@@ -237,11 +237,14 @@ peers_ready_cb (const struct GNUNET_PeerIdentity *peers, | |||
237 | { | 237 | { |
238 | struct GNUNET_RPS_Request_Handle *rh = cls; | 238 | struct GNUNET_RPS_Request_Handle *rh = cls; |
239 | 239 | ||
240 | rh->sampler_rh = NULL; | ||
240 | rh->ready_cb (rh->ready_cb_cls, | 241 | rh->ready_cb (rh->ready_cb_cls, |
241 | num_peers, | 242 | num_peers, |
242 | peers); | 243 | peers); |
243 | // TODO cleanup, sampler, rh, cancel stuff | 244 | GNUNET_RPS_stream_cancel (rh->srh); |
244 | // TODO screw this function. We can give the cb,cls directly to the sampler. | 245 | rh->srh = NULL; |
246 | RPS_sampler_destroy (rh->sampler); | ||
247 | rh->sampler = NULL; | ||
245 | } | 248 | } |
246 | 249 | ||
247 | 250 | ||
@@ -421,18 +424,13 @@ void | |||
421 | GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh) | 424 | GNUNET_RPS_stream_cancel (struct GNUNET_RPS_StreamRequestHandle *srh) |
422 | { | 425 | { |
423 | struct GNUNET_RPS_Handle *rps_handle; | 426 | struct GNUNET_RPS_Handle *rps_handle; |
424 | struct GNUNET_RPS_StreamRequestHandle *srh_iter; | ||
425 | 427 | ||
428 | GNUNET_assert (NULL != srh); | ||
426 | rps_handle = srh->rps_handle; | 429 | rps_handle = srh->rps_handle; |
427 | srh_iter = rps_handle->stream_requests_head; | 430 | GNUNET_CONTAINER_DLL_remove (rps_handle->stream_requests_head, |
428 | while (NULL != srh_iter && srh_iter != srh) srh_iter = srh_iter->next; | 431 | rps_handle->stream_requests_tail, |
429 | if (NULL != srh_iter) | 432 | srh); |
430 | { | 433 | GNUNET_free (srh); |
431 | GNUNET_CONTAINER_DLL_remove (rps_handle->stream_requests_head, | ||
432 | rps_handle->stream_requests_tail, | ||
433 | srh); | ||
434 | GNUNET_free (srh); | ||
435 | } | ||
436 | if (NULL == rps_handle->stream_requests_head) cancel_stream (rps_handle); | 434 | if (NULL == rps_handle->stream_requests_head) cancel_stream (rps_handle); |
437 | } | 435 | } |
438 | 436 | ||
@@ -480,20 +478,24 @@ handle_stream_input (void *cls, | |||
480 | struct GNUNET_RPS_Handle *h = cls; | 478 | struct GNUNET_RPS_Handle *h = cls; |
481 | const struct GNUNET_PeerIdentity *peers; | 479 | const struct GNUNET_PeerIdentity *peers; |
482 | uint64_t num_peers; | 480 | uint64_t num_peers; |
481 | struct GNUNET_RPS_StreamRequestHandle *srh_iter; | ||
482 | struct GNUNET_RPS_StreamRequestHandle *srh_next; | ||
483 | 483 | ||
484 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 484 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
485 | num_peers = ntohl (msg->num_peers); | 485 | num_peers = ntohl (msg->num_peers); |
486 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 486 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
487 | "Received %" PRIu64 " peer(s) from stream input.\n", | 487 | "Received %" PRIu64 " peer(s) from stream input.\n", |
488 | num_peers); | 488 | num_peers); |
489 | for (struct GNUNET_RPS_StreamRequestHandle *srh_iter = h->stream_requests_head; | 489 | srh_iter = h->stream_requests_head; |
490 | NULL != srh_iter; | 490 | while (NULL != srh_iter) |
491 | srh_iter = srh_iter->next) | ||
492 | { | 491 | { |
493 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n"); | 492 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Calling srh \n"); |
493 | /* Store next pointer - srh might be removed/freed in callback */ | ||
494 | srh_next = srh_iter->next; | ||
494 | srh_iter->ready_cb (srh_iter->ready_cb_cls, | 495 | srh_iter->ready_cb (srh_iter->ready_cb_cls, |
495 | num_peers, | 496 | num_peers, |
496 | peers); | 497 | peers); |
498 | srh_iter = srh_next; | ||
497 | } | 499 | } |
498 | 500 | ||
499 | if (NULL == h->stream_requests_head) | 501 | if (NULL == h->stream_requests_head) |
diff --git a/src/rps/test_rps.conf b/src/rps/test_rps.conf index c55930649..c7ac1f3b8 100644 --- a/src/rps/test_rps.conf +++ b/src/rps/test_rps.conf | |||
@@ -1,7 +1,7 @@ | |||
1 | [rps] | 1 | [rps] |
2 | #PREFIX = valgrind --leak-check=full --show-leak-kinds=all --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p | 2 | #PREFIX = valgrind --leak-check=full --show-leak-kinds=all --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p |
3 | #PREFIX = valgrind --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p | 3 | #PREFIX = valgrind --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p |
4 | #PREFIX = valgrind | 4 | #PREFIX = valgrind |
5 | UNIXPATH = $GNUNET_TMP/gnunet-service-rps.sock | 5 | UNIXPATH = $GNUNET_TMP/gnunet-service-rps.sock |
6 | HOME = $SERVICEHOME | 6 | HOME = $SERVICEHOME |
7 | # PORT = 2106 | 7 | # PORT = 2106 |