Fixed momory leak in RsDirUtil::getFileHash when the file doesn't exist.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8450 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2015-06-14 21:09:23 +00:00
parent 7563cb02d0
commit 87758c4043

View File

@ -646,14 +646,15 @@ bool RsDirUtil::hashFile(const std::string& filepath,
bool RsDirUtil::getFileHash(const std::string& filepath, RsFileHash &hash, uint64_t &size, RsThread *thread /*= NULL*/) bool RsDirUtil::getFileHash(const std::string& filepath, RsFileHash &hash, uint64_t &size, RsThread *thread /*= NULL*/)
{ {
FILE *fd; FILE *fd;
if (NULL == (fd = RsDirUtil::rs_fopen(filepath.c_str(), "rb")))
return false;
int len; int len;
SHA_CTX *sha_ctx = new SHA_CTX; SHA_CTX *sha_ctx = new SHA_CTX;
unsigned char sha_buf[SHA_DIGEST_LENGTH]; unsigned char sha_buf[SHA_DIGEST_LENGTH];
unsigned char gblBuf[512]; unsigned char gblBuf[512];
if (NULL == (fd = RsDirUtil::rs_fopen(filepath.c_str(), "rb")))
return false;
/* determine size */ /* determine size */
fseeko64(fd, 0, SEEK_END); fseeko64(fd, 0, SEEK_END);
size = ftello64(fd); size = ftello64(fd);