mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
gp2y0a: test for NULL alloc and clear allocated memory
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
parent
1483ab6a88
commit
370d43d1b3
@ -33,8 +33,17 @@ gp2y0a_context gp2y0a_init(uint8_t pin, float a_ref){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gp2y0a_context dev = (gp2y0a_context) malloc(sizeof(struct _gp2y0a_context));
|
||||
gp2y0a_context dev =
|
||||
(gp2y0a_context) malloc(sizeof(struct _gp2y0a_context));
|
||||
|
||||
if (!dev)
|
||||
{
|
||||
printf("%s: device context allocation failed (%d).\n",
|
||||
__FUNCTION__, mraa_rv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset((void *)dev, 0, sizeof(struct _gp2y0a_context));
|
||||
dev->pin = pin;
|
||||
dev->aio = mraa_aio_init(dev->pin);
|
||||
if(dev->aio == NULL){
|
||||
|
Loading…
x
Reference in New Issue
Block a user