From 72422e819bf6b67d47e5c6b98995b52f9eb3c751 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 5 May 2011 09:17:38 +0000 Subject: [PATCH] examples/nfc-dep-*: disconnect from NFC device on error. --- examples/nfc-dep-initiator.c | 6 ++++-- examples/nfc-dep-target.c | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index d58ab54..e3061b8 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -88,20 +88,22 @@ main (int argc, const char *argv[]) if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NBR_212, NULL, &nt)) { nfc_perror(pnd, "nfc_initiator_select_dep_target"); - return EXIT_FAILURE; + goto error; } print_nfc_target (nt, false); printf ("Sending: %s\n", abtTx); if (!nfc_initiator_transceive_bytes (pnd, abtTx, sizeof(abtTx), abtRx, &szRx)) { nfc_perror(pnd, "nfc_initiator_transceive_bytes"); - return EXIT_FAILURE; + goto error; } abtRx[szRx] = 0; printf ("Received: %s\n", abtRx); nfc_initiator_deselect_target (pnd); + +error: nfc_disconnect (pnd); return EXIT_SUCCESS; } diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index 39159f2..d5d67f5 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -120,13 +120,13 @@ main (int argc, const char *argv[]) printf ("Waiting for initiator request...\n"); if(!nfc_target_init (pnd, &nt, abtRx, &szRx)) { nfc_perror(pnd, "nfc_target_init"); - return EXIT_FAILURE; + goto error; } printf("Initiator request received. Waiting for data...\n"); if (!nfc_target_receive_bytes (pnd, abtRx, &szRx)) { nfc_perror(pnd, "nfc_target_receive_bytes"); - return EXIT_FAILURE; + goto error; } abtRx[szRx] = '\0'; printf ("Received: %s\n", abtRx); @@ -134,10 +134,11 @@ main (int argc, const char *argv[]) printf ("Sending: %s\n", abtTx); if (!nfc_target_send_bytes (pnd, abtTx, sizeof(abtTx))) { nfc_perror(pnd, "nfc_target_send_bytes"); - return EXIT_FAILURE; + goto error; } printf("Data sent.\n"); +error: nfc_disconnect (pnd); return EXIT_SUCCESS; }