From ae6062e5ba83c213616e32ad162ed143a170667e Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Tue, 5 Mar 2013 20:03:19 +0100 Subject: [PATCH] nfc_context_new(): replace err() by return, problem still in nfc_init()!! Not a good idea to call exit() from a library... Problem is now moved to void nfc_init() calling exit() This requires a change in API to return error rather than exiting... --- libnfc/nfc-internal.c | 2 +- libnfc/nfc.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) 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(); }