Check if nfc_init() returns a valid context

This fixes a potential segfault when libnfc is not correctly initialized
This commit is contained in:
Romuald Conty 2013-12-06 15:24:08 +01:00
parent 222ba1838c
commit e1a2b0225f

View file

@ -582,6 +582,10 @@ void mf_init(mfreader *r)
{
// Connect to the first NFC device
nfc_init(&context);
if (context == NULL) {
ERR("Unable to init libnfc (malloc)");
exit(EXIT_FAILURE);
}
r->pdi = nfc_open(context, NULL);
if (!r->pdi) {
printf("No NFC device found.\n");