diff --git a/libnfc/nfc-internal.c b/libnfc/nfc-internal.c index 5a40325..715c7ff 100644 --- a/libnfc/nfc-internal.c +++ b/libnfc/nfc-internal.c @@ -68,7 +68,7 @@ nfc_context_new(void) nfc_context *res = malloc(sizeof(*res)); if (!res) { - err(EXIT_FAILURE, "nfc_context_new: malloc"); + return NULL; } // Set default context values diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 20ed75d..e9a8a9c 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -172,7 +172,11 @@ void nfc_init(nfc_context **context) { *context = nfc_context_new(); - + if (!context) { + perror("malloc"); + // TODO: not a good idea to call exit() from a library, we should change API and return error + exit(EXIT_FAILURE); + } if (!nfc_drivers) nfc_drivers_init(); }