mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
applied removal of realloc to other files in file_sharing/ directory
This commit is contained in:
parent
0cb7778ceb
commit
5fbc263a36
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#include "dir_hierarchy.h"
|
#include "dir_hierarchy.h"
|
||||||
#include "filelist_io.h"
|
#include "filelist_io.h"
|
||||||
//#include "rsexpr.h"
|
#include "file_sharing_defaults.h"
|
||||||
|
|
||||||
//#define DEBUG_DIRECTORY_STORAGE 1
|
//#define DEBUG_DIRECTORY_STORAGE 1
|
||||||
|
|
||||||
@ -958,14 +958,12 @@ bool InternalFileHierarchyStorage::save(const std::string& fname)
|
|||||||
uint32_t buffer_size = 0 ;
|
uint32_t buffer_size = 0 ;
|
||||||
uint32_t buffer_offset = 0 ;
|
uint32_t buffer_offset = 0 ;
|
||||||
|
|
||||||
static const uint32_t BASE_TMP_SECTION_SIZE = 1000 ;
|
unsigned char *tmp_section_data = (unsigned char*)rs_malloc(FL_BASE_TMP_SECTION_SIZE) ;
|
||||||
|
|
||||||
unsigned char *tmp_section_data = (unsigned char*)rs_malloc(BASE_TMP_SECTION_SIZE) ;
|
|
||||||
|
|
||||||
if(!tmp_section_data)
|
if(!tmp_section_data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint32_t tmp_section_size = BASE_TMP_SECTION_SIZE ;
|
uint32_t tmp_section_size = FL_BASE_TMP_SECTION_SIZE ;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -724,8 +724,12 @@ bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinary
|
|||||||
allowed_subfiles++ ;
|
allowed_subfiles++ ;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *section_data = NULL;
|
unsigned char *section_data = (unsigned char *)rs_malloc(FL_BASE_TMP_SECTION_SIZE) ;
|
||||||
uint32_t section_size = 0;
|
|
||||||
|
if(!section_data)
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
uint32_t section_size = FL_BASE_TMP_SECTION_SIZE;
|
||||||
uint32_t section_offset = 0;
|
uint32_t section_offset = 0;
|
||||||
|
|
||||||
// we need to send:
|
// we need to send:
|
||||||
@ -751,11 +755,16 @@ bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinary
|
|||||||
|
|
||||||
// serialise directory subfiles, with info for each of them
|
// serialise directory subfiles, with info for each of them
|
||||||
|
|
||||||
|
unsigned char *file_section_data = (unsigned char *)rs_malloc(FL_BASE_TMP_SECTION_SIZE);
|
||||||
|
|
||||||
|
if(!file_section_data)
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
uint32_t file_section_size = FL_BASE_TMP_SECTION_SIZE;
|
||||||
|
|
||||||
for(uint32_t i=0;i<dir->subfiles.size();++i)
|
for(uint32_t i=0;i<dir->subfiles.size();++i)
|
||||||
{
|
{
|
||||||
unsigned char *file_section_data = NULL ;
|
|
||||||
uint32_t file_section_offset = 0 ;
|
uint32_t file_section_offset = 0 ;
|
||||||
uint32_t file_section_size = 0;
|
|
||||||
|
|
||||||
const InternalFileHierarchyStorage::FileEntry *file = mFileHierarchy->getFileEntry(dir->subfiles[i]) ;
|
const InternalFileHierarchyStorage::FileEntry *file = mFileHierarchy->getFileEntry(dir->subfiles[i]) ;
|
||||||
|
|
||||||
@ -774,12 +783,11 @@ bool LocalDirectoryStorage::serialiseDirEntry(const EntryIndex& indx,RsTlvBinary
|
|||||||
|
|
||||||
if(!FileListIO::writeField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_REMOTE_FILE_ENTRY,file_section_data,file_section_offset)) return false ;
|
if(!FileListIO::writeField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_REMOTE_FILE_ENTRY,file_section_data,file_section_offset)) return false ;
|
||||||
|
|
||||||
free(file_section_data) ;
|
|
||||||
|
|
||||||
#ifdef DEBUG_LOCAL_DIRECTORY_STORAGE
|
#ifdef DEBUG_LOCAL_DIRECTORY_STORAGE
|
||||||
std::cerr << " pushing subfile " << file->hash << ", array position=" << i << " indx=" << dir->subfiles[i] << std::endl;
|
std::cerr << " pushing subfile " << file->hash << ", array position=" << i << " indx=" << dir->subfiles[i] << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
free(file_section_data) ;
|
||||||
|
|
||||||
#ifdef DEBUG_LOCAL_DIRECTORY_STORAGE
|
#ifdef DEBUG_LOCAL_DIRECTORY_STORAGE
|
||||||
std::cerr << "Serialised dir entry to send for entry index " << (void*)(intptr_t)indx << ". Data size is " << section_size << " bytes" << std::endl;
|
std::cerr << "Serialised dir entry to send for entry index " << (void*)(intptr_t)indx << ". Data size is " << section_size << " bytes" << std::endl;
|
||||||
@ -857,14 +865,17 @@ bool RemoteDirectoryStorage::deserialiseUpdateDirEntry(const EntryIndex& indx,co
|
|||||||
// deserialise directory subfiles, with info for each of them
|
// deserialise directory subfiles, with info for each of them
|
||||||
|
|
||||||
std::vector<InternalFileHierarchyStorage::FileEntry> subfiles_array ;
|
std::vector<InternalFileHierarchyStorage::FileEntry> subfiles_array ;
|
||||||
|
unsigned char *file_section_data = (unsigned char *)rs_malloc(FL_BASE_TMP_SECTION_SIZE);
|
||||||
|
|
||||||
|
if(!file_section_data)
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
uint32_t file_section_size = FL_BASE_TMP_SECTION_SIZE;
|
||||||
|
|
||||||
for(uint32_t i=0;i<n_subfiles;++i)
|
for(uint32_t i=0;i<n_subfiles;++i)
|
||||||
{
|
{
|
||||||
// Read the full data section for the file
|
// Read the full data section for the file
|
||||||
|
|
||||||
unsigned char *file_section_data = NULL ;
|
|
||||||
uint32_t file_section_size = 0;
|
|
||||||
|
|
||||||
if(!FileListIO::readField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_REMOTE_FILE_ENTRY,file_section_data,file_section_size)) return false ;
|
if(!FileListIO::readField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_REMOTE_FILE_ENTRY,file_section_data,file_section_size)) return false ;
|
||||||
|
|
||||||
uint32_t file_section_offset = 0 ;
|
uint32_t file_section_offset = 0 ;
|
||||||
@ -879,10 +890,9 @@ bool RemoteDirectoryStorage::deserialiseUpdateDirEntry(const EntryIndex& indx,co
|
|||||||
|
|
||||||
f.file_modtime = modtime ;
|
f.file_modtime = modtime ;
|
||||||
|
|
||||||
free(file_section_data) ;
|
|
||||||
|
|
||||||
subfiles_array.push_back(f) ;
|
subfiles_array.push_back(f) ;
|
||||||
}
|
}
|
||||||
|
free(file_section_data) ;
|
||||||
|
|
||||||
RS_STACK_MUTEX(mDirStorageMtx) ;
|
RS_STACK_MUTEX(mDirStorageMtx) ;
|
||||||
#ifdef DEBUG_REMOTE_DIRECTORY_STORAGE
|
#ifdef DEBUG_REMOTE_DIRECTORY_STORAGE
|
||||||
|
@ -53,3 +53,5 @@ static const uint32_t NB_FRIEND_INDEX_BITS = 10 ; // Do not
|
|||||||
static const uint32_t NB_ENTRY_INDEX_BITS = 22 ; // Do not change this!
|
static const uint32_t NB_ENTRY_INDEX_BITS = 22 ; // Do not change this!
|
||||||
static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer. Depends on the two values just before. Dont change!
|
static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer. Depends on the two values just before. Dont change!
|
||||||
static const uint32_t DELAY_BEFORE_DROP_REQUEST = 600; // every 10 min
|
static const uint32_t DELAY_BEFORE_DROP_REQUEST = 600; // every 10 min
|
||||||
|
|
||||||
|
static const uint32_t FL_BASE_TMP_SECTION_SIZE = 1000 ;
|
||||||
|
@ -353,8 +353,12 @@ void HashStorage::locked_save()
|
|||||||
|
|
||||||
bool HashStorage::readHashStorageInfo(const unsigned char *data,uint32_t total_size,uint32_t& offset,HashStorageInfo& info) const
|
bool HashStorage::readHashStorageInfo(const unsigned char *data,uint32_t total_size,uint32_t& offset,HashStorageInfo& info) const
|
||||||
{
|
{
|
||||||
unsigned char *section_data = NULL ;
|
unsigned char *section_data = (unsigned char *)rs_malloc(FL_BASE_TMP_SECTION_SIZE) ;
|
||||||
uint32_t section_size = 0;
|
|
||||||
|
if(!section_data)
|
||||||
|
return false ;
|
||||||
|
|
||||||
|
uint32_t section_size = FL_BASE_TMP_SECTION_SIZE;
|
||||||
uint32_t section_offset = 0;
|
uint32_t section_offset = 0;
|
||||||
|
|
||||||
// This way, the entire section is either read or skipped. That avoids the risk of being stuck somewhere in the middle
|
// This way, the entire section is either read or skipped. That avoids the risk of being stuck somewhere in the middle
|
||||||
@ -375,9 +379,13 @@ bool HashStorage::readHashStorageInfo(const unsigned char *data,uint32_t total_s
|
|||||||
|
|
||||||
bool HashStorage::writeHashStorageInfo(unsigned char *& data,uint32_t& total_size,uint32_t& offset,const HashStorageInfo& info) const
|
bool HashStorage::writeHashStorageInfo(unsigned char *& data,uint32_t& total_size,uint32_t& offset,const HashStorageInfo& info) const
|
||||||
{
|
{
|
||||||
unsigned char *section_data = NULL ;
|
unsigned char *section_data = (unsigned char *)rs_malloc(FL_BASE_TMP_SECTION_SIZE) ;
|
||||||
|
|
||||||
|
if(!section_data)
|
||||||
|
return false ;
|
||||||
|
|
||||||
uint32_t section_offset = 0 ;
|
uint32_t section_offset = 0 ;
|
||||||
uint32_t section_size = 0;
|
uint32_t section_size = FL_BASE_TMP_SECTION_SIZE;
|
||||||
|
|
||||||
if(!FileListIO::writeField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_FILE_NAME ,info.filename )) return false ;
|
if(!FileListIO::writeField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_FILE_NAME ,info.filename )) return false ;
|
||||||
if(!FileListIO::writeField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_FILE_SIZE ,info.size )) return false ;
|
if(!FileListIO::writeField(section_data,section_size,section_offset,FILE_LIST_IO_TAG_FILE_SIZE ,info.size )) return false ;
|
||||||
|
Loading…
Reference in New Issue
Block a user