mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
added checks after mallocs in several files
This commit is contained in:
parent
46520b0e22
commit
9c6e7dfc13
15 changed files with 157 additions and 12 deletions
|
@ -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 ;
|
||||
|
|
|
@ -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 ;
|
||||
}
|
||||
|
|
|
@ -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 ;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue