From f8601886fdfae7f376b19393fa749f812af7ca87 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Sat, 16 Feb 2013 14:20:37 +0100 Subject: [PATCH] Adds nfc_free() function to freed allocated buffers Fixes issue 228 (Thanks to Alex Lian) --- include/nfc/nfc.h | 1 + libnfc/nfc.c | 13 ++++++++++++- utils/nfc-scan-device.c | 2 +- utils/nfc-utils.c | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index 5507140..74596b5 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -131,6 +131,7 @@ extern "C" { NFC_EXPORT void iso14443a_crc_append(uint8_t *pbtData, size_t szLen); NFC_EXPORT uint8_t *iso14443a_locate_historical_bytes(uint8_t *pbtAts, size_t szAts, size_t *pszTk); + NFC_EXPORT void nfc_free(void *p); NFC_EXPORT const char *nfc_version(void); NFC_EXPORT int nfc_device_get_information_about(nfc_device *pnd, char **buf); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index c352a01..bdf1a4f 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -1168,6 +1168,17 @@ nfc_version(void) #endif // GIT_REVISION } +/** @ingroup misc + * @brief Free buffer allocated by libnfc + * + * @param pointer on buffer that need to be freed + */ +void +nfc_free(void *p) +{ + free(p); +} + /** @ingroup misc * @brief Print information about NFC device * @return Upon successful return, this function returns the number of characters printed (excluding the null byte used to end output to strings), otherwise returns libnfc's error code (negative value) @@ -1255,7 +1266,7 @@ str_nfc_modulation_type(const nfc_modulation_type nmt) * @param nt \a nfc_target struct to print * @param buf pointer where string will be allocated, then nfc target information printed * - * @warning *buf must be freed. + * @warning *buf must be freed using nfc_free() */ int str_nfc_target(char **buf, const nfc_target nt, bool verbose) diff --git a/utils/nfc-scan-device.c b/utils/nfc-scan-device.c index 0ff6393..12693b1 100644 --- a/utils/nfc-scan-device.c +++ b/utils/nfc-scan-device.c @@ -125,7 +125,7 @@ main(int argc, const char *argv[]) if (verbose) { if (nfc_device_get_information_about(pnd, &strinfo) >= 0) { printf("%s", strinfo); - free(strinfo); + nfc_free(strinfo); } } nfc_close(pnd); diff --git a/utils/nfc-utils.c b/utils/nfc-utils.c index deb51e7..a56b0f7 100644 --- a/utils/nfc-utils.c +++ b/utils/nfc-utils.c @@ -120,5 +120,5 @@ print_nfc_target(const nfc_target nt, bool verbose) char *s; str_nfc_target(&s, nt, verbose); printf("%s", s); - free(s); + nfc_free(s); }