mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-09 09:35:32 -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
|
@ -46,6 +46,7 @@
|
|||
#include <fstream>
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsmemory.h"
|
||||
#include "util/rsstring.h"
|
||||
|
||||
//
|
||||
|
@ -194,7 +195,12 @@ int pqistore::writePkt(RsItem *pqi)
|
|||
#endif
|
||||
|
||||
uint32_t pktsize = rsSerialiser->size(pqi);
|
||||
void *ptr = malloc(pktsize);
|
||||
|
||||
RsTemporaryMemory ptr(pktsize) ;
|
||||
|
||||
if(ptr == NULL)
|
||||
return 0 ;
|
||||
|
||||
if (!(rsSerialiser->serialise(pqi, ptr, &pktsize)))
|
||||
{
|
||||
#ifdef PQISTORE_DEBUG
|
||||
|
@ -203,7 +209,6 @@ int pqistore::writePkt(RsItem *pqi)
|
|||
pqioutput(PQL_ALERT, pqistorezone, out);
|
||||
#endif
|
||||
|
||||
free(ptr);
|
||||
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
|
||||
delete pqi;
|
||||
return 0;
|
||||
|
@ -218,7 +223,6 @@ int pqistore::writePkt(RsItem *pqi)
|
|||
pqi -> print_string(out);
|
||||
pqioutput(PQL_ALERT, pqistorezone, out);
|
||||
|
||||
free(ptr);
|
||||
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
|
||||
delete pqi;
|
||||
return 0;
|
||||
|
@ -232,7 +236,6 @@ int pqistore::writePkt(RsItem *pqi)
|
|||
pqi -> print_string(out);
|
||||
pqioutput(PQL_ALERT, pqistorezone, out);
|
||||
|
||||
free(ptr);
|
||||
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
|
||||
delete pqi;
|
||||
|
||||
|
@ -250,7 +253,6 @@ int pqistore::writePkt(RsItem *pqi)
|
|||
pqioutput(PQL_ALERT, pqistorezone, out);
|
||||
#endif
|
||||
|
||||
free(ptr);
|
||||
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
|
||||
delete pqi;
|
||||
|
||||
|
@ -262,7 +264,6 @@ int pqistore::writePkt(RsItem *pqi)
|
|||
pqioutput(PQL_DEBUG_BASIC, pqistorezone, out);
|
||||
#endif
|
||||
|
||||
free(ptr);
|
||||
if (!(bio_flags & BIN_FLAGS_NO_DELETE))
|
||||
delete pqi;
|
||||
|
||||
|
@ -288,7 +289,10 @@ int pqistore::readPkt(RsItem **item_out)
|
|||
|
||||
// initial read size: basic packet.
|
||||
int blen = getRsPktBaseSize();
|
||||
void *block = malloc(blen);
|
||||
void *block = rs_safe_malloc(blen);
|
||||
|
||||
if(block == NULL)
|
||||
return false ;
|
||||
|
||||
int tmplen;
|
||||
/* we have the header */
|
||||
|
@ -495,7 +499,10 @@ int pqiSSLstore::readPkt(RsItem **item_out)
|
|||
|
||||
// initial read size: basic packet.
|
||||
int blen = getRsPktBaseSize();
|
||||
void *block = malloc(blen);
|
||||
void *block = rs_safe_malloc(blen);
|
||||
|
||||
if(block == NULL)
|
||||
return false ;
|
||||
|
||||
int tmplen;
|
||||
/* we have the header */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue