check malloc return value

see e0999ace78
This commit is contained in:
Thomas Bernard 2015-09-04 18:57:24 +02:00
parent 8ecb5fcd92
commit 3101b14d71
1 changed files with 16 additions and 3 deletions

View File

@ -1,7 +1,7 @@
/* $Id: upnpreplyparse.c,v 1.18 2014/11/05 05:36:08 nanard Exp $ */ /* $Id: upnpreplyparse.c,v 1.19 2015/07/15 10:29:11 nanard Exp $ */
/* MiniUPnP project /* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2014 Thomas Bernard * (c) 2006-2015 Thomas Bernard
* This software is subject to the conditions detailed * This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */ * in the LICENCE file provided within the distribution */
@ -40,6 +40,15 @@ NameValueParserEndElt(void * d, const char * name, int l)
/* standard case. Limited to n chars strings */ /* standard case. Limited to n chars strings */
l = data->cdatalen; l = data->cdatalen;
nv = malloc(sizeof(struct NameValue)); nv = malloc(sizeof(struct NameValue));
if(nv == NULL)
{
/* malloc error */
#ifdef DEBUG
fprintf(stderr, "%s: error allocating memory",
"NameValueParserEndElt");
#endif /* DEBUG */
return;
}
if(l>=(int)sizeof(nv->value)) if(l>=(int)sizeof(nv->value))
l = sizeof(nv->value) - 1; l = sizeof(nv->value) - 1;
strncpy(nv->name, data->curelt, 64); strncpy(nv->name, data->curelt, 64);
@ -72,6 +81,10 @@ NameValueParserGetData(void * d, const char * datas, int l)
if(!data->portListing) if(!data->portListing)
{ {
/* malloc error */ /* malloc error */
#ifdef DEBUG
fprintf(stderr, "%s: error allocating memory",
"NameValueParserGetData");
#endif /* DEBUG */
return; return;
} }
memcpy(data->portListing, datas, l); memcpy(data->portListing, datas, l);
@ -180,5 +193,5 @@ DisplayNameValueList(char * buffer, int bufsize)
} }
ClearNameValueList(&pdata); ClearNameValueList(&pdata);
} }
#endif #endif /* DEBUG */