diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-10-03 18:54:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-10-03 18:54:58 +0000 |
commit | 79266195ab614b5b3e4a168b93fef1cf43d6400a (patch) | |
tree | be76f18d138df68d2f5af7b280c13561ef18bc1c /src/nat/nat_test.c | |
parent | 78f5d7d58f696abf22263d4da685d65f551b4750 (diff) | |
download | gnunet-79266195ab614b5b3e4a168b93fef1cf43d6400a.tar.gz gnunet-79266195ab614b5b3e4a168b93fef1cf43d6400a.zip |
-fix NPE in NAT test
Diffstat (limited to 'src/nat/nat_test.c')
-rw-r--r-- | src/nat/nat_test.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c index 90f06be5c..25945cef0 100644 --- a/src/nat/nat_test.c +++ b/src/nat/nat_test.c | |||
@@ -142,7 +142,7 @@ struct GNUNET_NAT_Test | |||
142 | * Identity of task for the listen socket (if any) | 142 | * Identity of task for the listen socket (if any) |
143 | */ | 143 | */ |
144 | GNUNET_SCHEDULER_TaskIdentifier ltask; | 144 | GNUNET_SCHEDULER_TaskIdentifier ltask; |
145 | 145 | ||
146 | /** | 146 | /** |
147 | * Task identifier for the timeout (if any) | 147 | * Task identifier for the timeout (if any) |
148 | */ | 148 | */ |
@@ -372,31 +372,33 @@ addr_cb (void *cls, | |||
372 | 372 | ||
373 | 373 | ||
374 | /** | 374 | /** |
375 | * Timeout task for a nat test. | 375 | * Timeout task for a nat test. |
376 | * Calls the report-callback with a timeout return value | 376 | * Calls the report-callback with a timeout return value |
377 | * | 377 | * |
378 | * Destroys the nat handle after the callback has been processed. | 378 | * Destroys the nat handle after the callback has been processed. |
379 | * | 379 | * |
380 | * @param cls handle to the timed out NAT test | 380 | * @param cls handle to the timed out NAT test |
381 | * @param tc not used | 381 | * @param tc not used |
382 | */ | 382 | */ |
383 | static void | 383 | static void |
384 | do_timeout (void *cls, | 384 | do_timeout (void *cls, |
385 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 385 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
386 | { | 386 | { |
387 | struct GNUNET_NAT_Test *nh = (struct GNUNET_NAT_Test *) cls; | 387 | struct GNUNET_NAT_Test *nh = cls; |
388 | 388 | ||
389 | nh->ttask = GNUNET_SCHEDULER_NO_TASK; | 389 | nh->ttask = GNUNET_SCHEDULER_NO_TASK; |
390 | nh->report (nh->report_cls, (GNUNET_NAT_ERROR_SUCCESS == nh->status)? GNUNET_NAT_ERROR_TIMEOUT: nh->status ); | 390 | nh->report (nh->report_cls, |
391 | 391 | (GNUNET_NAT_ERROR_SUCCESS == nh->status) | |
392 | GNUNET_NAT_test_stop(nh); | 392 | ? GNUNET_NAT_ERROR_TIMEOUT |
393 | : nh->status); | ||
394 | GNUNET_NAT_test_stop (nh); | ||
393 | } | 395 | } |
394 | 396 | ||
395 | 397 | ||
396 | /** | 398 | /** |
397 | * Start testing if NAT traversal works using the | 399 | * Start testing if NAT traversal works using the |
398 | * given configuration (IPv4-only). | 400 | * given configuration (IPv4-only). |
399 | * | 401 | * |
400 | * ALL failures are reported directly to the report callback | 402 | * ALL failures are reported directly to the report callback |
401 | * | 403 | * |
402 | * @param cfg configuration for the NAT traversal | 404 | * @param cfg configuration for the NAT traversal |
@@ -483,17 +485,20 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
483 | "NAT test listens on port %u (%s)\n", | 485 | "NAT test listens on port %u (%s)\n", |
484 | bnd_port, | 486 | bnd_port, |
485 | (GNUNET_YES == is_tcp) ? "tcp" : "udp"); | 487 | (GNUNET_YES == is_tcp) ? "tcp" : "udp"); |
486 | nh->nat = GNUNET_NAT_register (cfg, is_tcp, adv_port, 1, addrs, addrlens, | 488 | nh->nat = GNUNET_NAT_register (cfg, is_tcp, adv_port, 1, |
487 | &addr_cb, NULL, nh); | 489 | addrs, addrlens, |
490 | &addr_cb, NULL, nh); | ||
488 | if (NULL == nh->nat) | 491 | if (NULL == nh->nat) |
489 | { | 492 | { |
490 | LOG (GNUNET_ERROR_TYPE_ERROR, | 493 | LOG (GNUNET_ERROR_TYPE_ERROR, |
491 | _("NAT test failed to start NAT library\n")); | 494 | _("NAT test failed to start NAT library\n")); |
492 | if (GNUNET_SCHEDULER_NO_TASK != nh->ltask){ | 495 | if (GNUNET_SCHEDULER_NO_TASK != nh->ltask) |
496 | { | ||
493 | GNUNET_SCHEDULER_cancel (nh->ltask); | 497 | GNUNET_SCHEDULER_cancel (nh->ltask); |
494 | nh->ltask = GNUNET_SCHEDULER_NO_TASK; | 498 | nh->ltask = GNUNET_SCHEDULER_NO_TASK; |
495 | } | 499 | } |
496 | if (NULL != nh->lsock){ | 500 | if (NULL != nh->lsock) |
501 | { | ||
497 | GNUNET_NETWORK_socket_close (nh->lsock); | 502 | GNUNET_NETWORK_socket_close (nh->lsock); |
498 | nh->lsock = NULL; | 503 | nh->lsock = NULL; |
499 | } | 504 | } |
@@ -539,7 +544,8 @@ GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst) | |||
539 | GNUNET_SCHEDULER_cancel (tst->ltask); | 544 | GNUNET_SCHEDULER_cancel (tst->ltask); |
540 | if (NULL != tst->lsock) | 545 | if (NULL != tst->lsock) |
541 | GNUNET_NETWORK_socket_close (tst->lsock); | 546 | GNUNET_NETWORK_socket_close (tst->lsock); |
542 | GNUNET_NAT_unregister (tst->nat); | 547 | if (NULL != tst->nat) |
548 | GNUNET_NAT_unregister (tst->nat); | ||
543 | GNUNET_free (tst); | 549 | GNUNET_free (tst); |
544 | } | 550 | } |
545 | 551 | ||