added checks after mallocs in several files

This commit is contained in:
csoler 2016-01-11 23:49:00 -05:00
parent 46520b0e22
commit 9c6e7dfc13
15 changed files with 157 additions and 12 deletions

View file

@ -349,6 +349,13 @@ RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const
// then duplicate the memory chunk
item->data_bytes = (uint8_t*)malloc(data_size) ;
if(item->data_bytes == NULL)
{
std::cerr << "(EE) memory allocation error for " << data_size << " bytes in " << __PRETTY_FUNCTION__ << std::endl;
return NULL ;
}
memcpy(item->data_bytes,data_bytes,data_size) ;
return item ;

View file

@ -195,6 +195,12 @@ class RsGRouterTransactionChunkItem: public RsGRouterTransactionItem, public RsG
RsGRouterTransactionChunkItem *item = new RsGRouterTransactionChunkItem ;
*item = *this ; // copy all fields
item->chunk_data = (uint8_t*)malloc(chunk_size) ; // deep copy memory chunk
if(item->chunk_data == NULL)
{
std::cerr << "(EE) Memory allocation error in " << __PRETTY_FUNCTION__ << " for size " << chunk_size << std::endl;
return NULL ;
}
memcpy(item->chunk_data,chunk_data,chunk_size) ;
return item ;
}

View file

@ -1922,6 +1922,12 @@ bool p3GRouter::sendData(const RsGxsId& destination,const GRouterServiceId& clie
RsGRouterGenericDataItem *data_item = new RsGRouterGenericDataItem ;
data_item->data_bytes = (uint8_t*)malloc(data_size) ;
if(data_item->data_bytes == NULL)
{
std::cerr << "(EE) memory allocaiton error for " << data_size << " bytes in " << __PRETTY_FUNCTION__<< std::endl;
return false ;
}
memcpy(data_item->data_bytes,data,data_size) ;
data_item->data_size = data_size ;