Fix unclosed file handle in Util::createXML

File handle for input file was not closed in case of errors.
Added fclose() to all error cases.
This commit is contained in:
Sude 2018-12-20 11:10:42 +02:00
parent 8683fe0a4e
commit f559c6c014

View File

@ -146,6 +146,7 @@ int Util::createXML(std::string filepath, uintmax_t chunk_size, std::string xml_
if(!rhash_context) if(!rhash_context)
{ {
std::cerr << "error: couldn't initialize rhash context" << std::endl; std::cerr << "error: couldn't initialize rhash context" << std::endl;
fclose(infile);
return res; return res;
} }
char rhash_result[rhash_get_hash_length(RHASH_MD5)]; char rhash_result[rhash_get_hash_length(RHASH_MD5)];
@ -160,6 +161,7 @@ int Util::createXML(std::string filepath, uintmax_t chunk_size, std::string xml_
if (chunk == NULL) if (chunk == NULL)
{ {
std::cerr << "Memory error" << std::endl; std::cerr << "Memory error" << std::endl;
fclose(infile);
return res; return res;
} }
size = fread(chunk, 1, chunk_size, infile); size = fread(chunk, 1, chunk_size, infile);
@ -167,6 +169,7 @@ int Util::createXML(std::string filepath, uintmax_t chunk_size, std::string xml_
{ {
std::cerr << "Read error" << std::endl; std::cerr << "Read error" << std::endl;
free(chunk); free(chunk);
fclose(infile);
return res; return res;
} }