From b83a1f18d89238ef203fa4a71844862d4b8551ee Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 9 Sep 2014 17:11:37 +0000 Subject: [PATCH] fixed memory leak/missing fclose. Patch from Vaio git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7510 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/dbase/findex.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index 870f1f490..f4948d0e2 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -769,21 +769,23 @@ int FileIndex::loadIndex(const std::string& filename, const RsFileHash& expected /* load file into memory, close file */ uint8_t *compressed_data = new uint8_t[size] ; - - if(compressed_data == NULL) + if(!compressed_data) { std::cerr << "FileIndex::loadIndex(): can't allocate memory for " << size << " bytes." << std::endl; - return 0 ; + fclose(file); + return 0; } int bytesread = 0 ; if(size != (bytesread = fread(compressed_data,1,size,file))) { std::cerr << "FileIndex::loadIndex(): can't read " << size << " bytes from file " << filename << ". Only " << bytesread << " actually read." << std::endl; - return 0 ; + fclose(file); + delete[] compressed_data; + return 0; } - fclose(file) ; + fclose(file); - RsFileHash tmpout = RsDirUtil::sha1sum((unsigned char *)(compressed_data),size); + RsFileHash tmpout = RsDirUtil::sha1sum((unsigned char *)(compressed_data),size); // /* calculate hash */ // unsigned char sha_buf[SHA_DIGEST_LENGTH];