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/rps_api.c | |
parent | 1ca9b7ee09328a33f5f428ee3c37acc8479e31fa (diff) | |
download | gnunet-564df39557f1a69280f36ff5173807856ff41067.tar.gz gnunet-564df39557f1a69280f36ff5173807856ff41067.zip |
RPS: Cleanup datastructures, NULL out freed pointers
Diffstat (limited to 'src/rps/rps_api.c')
-rw-r--r-- | src/rps/rps_api.c | 32 |
1 files changed, 17 insertions, 15 deletions
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) |