Adds nfc_free() function to freed allocated buffers
Fixes issue 228 (Thanks to Alex Lian)
This commit is contained in:
parent
ffd5928dc6
commit
f8601886fd
4 changed files with 15 additions and 3 deletions
|
@ -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);
|
||||
|
||||
|
|
13
libnfc/nfc.c
13
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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue