Skip to content

Commit

Permalink
[loadfile] free over-allocated memory from growing buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Marshall authored and Karlson2k committed Jul 23, 2013
1 parent 1a2e6ae commit 07ba551
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions xbmc/utils/FileUtils.cpp
Expand Up @@ -209,6 +209,20 @@ unsigned int CFileUtils::LoadFile(const std::string &filename, void* &outputBuff
return 0;
}

if (total_read + 1 < inputBuffSize)
{
/* free extra memory if more than 1 byte (cases 1 and 3) */
unsigned char *tempinputBuff = (unsigned char *)realloc(inputBuff, total_read);
if (!tempinputBuff)
{
/* just a precaution, shouldn't really happen */
CLog::Log(LOGERROR, "%s unable to reallocate buffer for file \"%s\"", __FUNCTION__, filename.c_str());
free(inputBuff);
return 0;
}
inputBuff = tempinputBuff;
}

outputBuffer = (void *) inputBuff;
return total_read;
}
Expand Down

0 comments on commit 07ba551

Please sign in to comment.