mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
added a new method rs_malloc that checks its arguments and prints a stacktrace on error/weird call. Changed the code everywhere to use this instead of malloc. Removed some mallocs and replaced with RsTemporaryMemory
This commit is contained in:
parent
9c6e7dfc13
commit
d13526facd
39 changed files with 274 additions and 132 deletions
|
@ -86,9 +86,8 @@ RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransac
|
|||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
if( NULL == (item->chunk_data = (uint8_t*)malloc(item->chunk_size)))
|
||||
if( NULL == (item->chunk_data = (uint8_t*)rs_safe_malloc(item->chunk_size)))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": Cannot allocate memory for chunk " << item->chunk_size << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
@ -150,9 +149,8 @@ RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataI
|
|||
return NULL ;
|
||||
}
|
||||
|
||||
if( NULL == (item->data_bytes = (uint8_t*)malloc(item->data_size)))
|
||||
if( NULL == (item->data_bytes = (uint8_t*)rs_safe_malloc(item->data_size)))
|
||||
{
|
||||
std::cerr << __PRETTY_FUNCTION__ << ": Cannot allocate memory for chunk " << item->data_size << std::endl;
|
||||
delete item;
|
||||
return NULL ;
|
||||
}
|
||||
|
@ -348,13 +346,10 @@ RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const
|
|||
|
||||
// then duplicate the memory chunk
|
||||
|
||||
item->data_bytes = (uint8_t*)malloc(data_size) ;
|
||||
item->data_bytes = (uint8_t*)rs_safe_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) ;
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
|
@ -194,13 +196,11 @@ 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
|
||||
item->chunk_data = (uint8_t*)rs_safe_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 ;
|
||||
}
|
||||
|
|
|
@ -1121,13 +1121,11 @@ bool p3GRouter::locked_sendTransactionData(const RsPeerId& pid,const RsGRouterTr
|
|||
std::cerr << " sending to tunnel vpid " << pid << std::endl;
|
||||
#endif
|
||||
uint32_t turtle_data_size = trans_item.serial_size() ;
|
||||
uint8_t *turtle_data = (uint8_t*)malloc(turtle_data_size) ;
|
||||
uint8_t *turtle_data = (uint8_t*)rs_safe_malloc(turtle_data_size) ;
|
||||
|
||||
if(turtle_data == NULL)
|
||||
{
|
||||
std::cerr << " ERROR: Cannot allocate turtle data memory for size " << turtle_data_size << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
if(!trans_item.serialise(turtle_data,turtle_data_size))
|
||||
{
|
||||
std::cerr << " ERROR: cannot serialise RsGRouterTransactionChunkItem." << std::endl;
|
||||
|
@ -1304,14 +1302,13 @@ bool p3GRouter::sliceDataItem(RsGRouterAbstractMsgItem *item,std::list<RsGRouter
|
|||
chunk_item->total_size = size;
|
||||
chunk_item->chunk_start= offset;
|
||||
chunk_item->chunk_size = chunk_size ;
|
||||
chunk_item->chunk_data = (uint8_t*)malloc(chunk_size) ;
|
||||
chunk_item->chunk_data = (uint8_t*)rs_safe_malloc(chunk_size) ;
|
||||
#ifdef GROUTER_DEBUG
|
||||
std::cerr << " preparing to send a chunk [" << offset << " -> " << offset + chunk_size << " / " << size << "]" << std::endl;
|
||||
#endif
|
||||
|
||||
if(chunk_item->chunk_data == NULL)
|
||||
{
|
||||
std::cerr << " ERROR: Cannot allocate memory for size " << chunk_size << std::endl;
|
||||
delete chunk_item;
|
||||
throw ;
|
||||
}
|
||||
|
@ -1921,13 +1918,11 @@ bool p3GRouter::sendData(const RsGxsId& destination,const GRouterServiceId& clie
|
|||
|
||||
RsGRouterGenericDataItem *data_item = new RsGRouterGenericDataItem ;
|
||||
|
||||
data_item->data_bytes = (uint8_t*)malloc(data_size) ;
|
||||
data_item->data_bytes = (uint8_t*)rs_safe_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