spi.c: check memory allocation for context was succesful
authorBrendan Le Foll <brendan.le.foll@intel.com>
Wed, 19 Nov 2014 23:45:35 +0000 (23:45 +0000)
committerBrendan Le Foll <brendan.le.foll@intel.com>
Wed, 19 Nov 2014 23:46:30 +0000 (23:46 +0000)
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
src/spi/spi.c

index 87c8399..c416083 100644 (file)
@@ -105,6 +105,10 @@ mraa_spi_init(int bus)
     }
 
     mraa_spi_context dev = (mraa_spi_context) malloc(sizeof(struct _spi));
+    if (dev == NULL) {
+        syslog(LOG_CRIT, "spi: Failed to allocate memory for context");
+        return NULL;
+    }
     memset(dev, 0, sizeof(struct _spi));
 
     char path[MAX_SIZE];