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
|
@ -1,5 +1,6 @@
|
|||
#include "SpeexProcessor.h"
|
||||
|
||||
#include <util/rsmemory.h>
|
||||
#include <speex/speex.h>
|
||||
#include <speex/speex_preprocess.h>
|
||||
|
||||
|
@ -350,7 +351,11 @@ void SpeexOutputProcessor::putNetworkPacket(QString name, QByteArray packet) {
|
|||
if (userJitterHash.contains(name)) {
|
||||
userJitter = userJitterHash.value(name);
|
||||
} else {
|
||||
userJitter = (SpeexJitter*)malloc(sizeof(SpeexJitter));
|
||||
userJitter = (SpeexJitter*)rs_safe_malloc(sizeof(SpeexJitter));
|
||||
|
||||
if(!userJitter)
|
||||
return ;
|
||||
|
||||
speex_jitter_init(userJitter, speex_decoder_init(&speex_wb_mode), SAMPLING_RATE);
|
||||
int on = 1;
|
||||
speex_decoder_ctl(userJitter->dec, SPEEX_SET_ENH, &on);
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <QBuffer>
|
||||
#include <QImage>
|
||||
|
||||
#include "util/rsmemory.h"
|
||||
|
||||
#include "VideoProcessor.h"
|
||||
#include "QVideoDevice.h"
|
||||
|
||||
|
@ -384,7 +386,10 @@ bool JPEGVideo::encodeData(const QImage& image,uint32_t /* size_hint */,RsVOIPDa
|
|||
buffer.open(QIODevice::WriteOnly) ;
|
||||
encoded_frame.save(&buffer,"JPEG") ;
|
||||
|
||||
voip_chunk.data = malloc(HEADER_SIZE + qb.size());
|
||||
voip_chunk.data = rs_safe_malloc(HEADER_SIZE + qb.size());
|
||||
|
||||
if(!voip_chunk.data)
|
||||
return false ;
|
||||
|
||||
// build header
|
||||
uint32_t flags = differential_frame ? JPEG_VIDEO_FLAGS_DIFFERENTIAL_FRAME : 0x0 ;
|
||||
|
@ -679,7 +684,11 @@ bool FFmpegVideo::encodeData(const QImage& image, uint32_t target_encoding_bitra
|
|||
|
||||
if(got_output)
|
||||
{
|
||||
voip_chunk.data = malloc(pkt.size + HEADER_SIZE) ;
|
||||
voip_chunk.data = rs_safe_malloc(pkt.size + HEADER_SIZE) ;
|
||||
|
||||
if(!voip_chunk.data)
|
||||
return false ;
|
||||
|
||||
uint32_t flags = 0;
|
||||
|
||||
((unsigned char *)voip_chunk.data)[0] = VideoProcessor::VIDEO_PROCESSOR_CODEC_ID_MPEG_VIDEO & 0xff ;
|
||||
|
|
|
@ -280,11 +280,10 @@ int p3VOIP::sendVoipData(const RsPeerId& peer_id,const RsVOIPDataChunk& chunk)
|
|||
std::cerr << "Cannot allocate RsVOIPDataItem !" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
item->voip_data = malloc(chunk.size) ;
|
||||
item->voip_data = rs_safe_malloc(chunk.size) ;
|
||||
|
||||
if(item->voip_data == NULL)
|
||||
{
|
||||
std::cerr << "Cannot allocate RsVOIPDataItem.voip_data of size " << chunk.size << " !" << std::endl;
|
||||
delete item ;
|
||||
return false ;
|
||||
}
|
||||
|
@ -432,11 +431,10 @@ bool p3VOIP::getIncomingData(const RsPeerId& peer_id,std::vector<RsVOIPDataChunk
|
|||
{
|
||||
RsVOIPDataChunk chunk ;
|
||||
chunk.size = (*it2)->data_size ;
|
||||
chunk.data = malloc((*it2)->data_size) ;
|
||||
chunk.data = rs_safe_malloc((*it2)->data_size) ;
|
||||
|
||||
if(chunk.data == NULL)
|
||||
{
|
||||
std::cerr << "(EE) p3VOIP::getIncomingData(): error. Cannot allocate memory for chunk of size " << chunk.size << std::endl;
|
||||
delete *it2 ;
|
||||
continue ;
|
||||
}
|
||||
|
|
|
@ -450,7 +450,11 @@ RsVOIPDataItem::RsVOIPDataItem(void *data, uint32_t pktsize)
|
|||
if(data_size > rssize || rssize - data_size < offset)
|
||||
throw std::runtime_error("Not enough space.") ;
|
||||
|
||||
voip_data = malloc(data_size) ;
|
||||
voip_data = rs_safe_malloc(data_size) ;
|
||||
|
||||
if(!voip_data)
|
||||
throw std::runtime_error("Serialization error.") ;
|
||||
|
||||
memcpy(voip_data,&((uint8_t*)data)[offset],data_size) ;
|
||||
offset += data_size ;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue