Skip to content

Commit

Permalink
Adds nfc_free() function to freed allocated buffers
Browse files Browse the repository at this point in the history
Fixes issue 228 (Thanks to Alex Lian)
  • Loading branch information
neomilium committed Feb 16, 2013
1 parent ffd5928 commit f860188
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/nfc/nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 12 additions & 1 deletion libnfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion utils/nfc-scan-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion utils/nfc-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit f860188

Please sign in to comment.