Skip to content

Commit

Permalink
Fix leaks in info module.
Browse files Browse the repository at this point in the history
*LoadFileCallback() all leaked between retries.

infoPgArchiveId() leaked a String.
  • Loading branch information
dwsteele committed Apr 26, 2022
1 parent 36b0a9f commit 78e912a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 39 deletions.
28 changes: 16 additions & 12 deletions src/info/infoArchive.c
Expand Up @@ -213,7 +213,7 @@ typedef struct InfoArchiveLoadFileData
} InfoArchiveLoadFileData;

static bool
infoArchiveLoadFileCallback(void *data, unsigned int try)
infoArchiveLoadFileCallback(void *const data, const unsigned int try)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM_P(VOID, data);
Expand All @@ -222,24 +222,28 @@ infoArchiveLoadFileCallback(void *data, unsigned int try)

ASSERT(data != NULL);

InfoArchiveLoadFileData *loadData = (InfoArchiveLoadFileData *)data;
InfoArchiveLoadFileData *const loadData = data;
bool result = false;

if (try < 2)
{
// Construct filename based on try
const String *fileName = try == 0 ? loadData->fileName : strNewFmt("%s" INFO_COPY_EXT, strZ(loadData->fileName));
MEM_CONTEXT_TEMP_BEGIN()
{
// Construct filename based on try
const String *const fileName = try == 0 ? loadData->fileName : strNewFmt("%s" INFO_COPY_EXT, strZ(loadData->fileName));

// Attempt to load the file
IoRead *read = storageReadIo(storageNewReadP(loadData->storage, fileName));
cipherBlockFilterGroupAdd(ioReadFilterGroup(read), loadData->cipherType, cipherModeDecrypt, loadData->cipherPass);
// Attempt to load the file
IoRead *const read = storageReadIo(storageNewReadP(loadData->storage, fileName));
cipherBlockFilterGroupAdd(ioReadFilterGroup(read), loadData->cipherType, cipherModeDecrypt, loadData->cipherPass);

MEM_CONTEXT_BEGIN(loadData->memContext)
{
loadData->infoArchive = infoArchiveNewLoad(read);
result = true;
MEM_CONTEXT_BEGIN(loadData->memContext)
{
loadData->infoArchive = infoArchiveNewLoad(read);
result = true;
}
MEM_CONTEXT_END();
}
MEM_CONTEXT_END();
MEM_CONTEXT_TEMP_END();
}

FUNCTION_LOG_RETURN(BOOL, result);
Expand Down
28 changes: 16 additions & 12 deletions src/info/infoBackup.c
Expand Up @@ -561,7 +561,7 @@ typedef struct InfoBackupLoadFileData
} InfoBackupLoadFileData;

static bool
infoBackupLoadFileCallback(void *data, unsigned int try)
infoBackupLoadFileCallback(void *const data, const unsigned int try)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM_P(VOID, data);
Expand All @@ -570,24 +570,28 @@ infoBackupLoadFileCallback(void *data, unsigned int try)

ASSERT(data != NULL);

InfoBackupLoadFileData *loadData = (InfoBackupLoadFileData *)data;
InfoBackupLoadFileData *const loadData = data;
bool result = false;

if (try < 2)
{
// Construct filename based on try
const String *fileName = try == 0 ? loadData->fileName : strNewFmt("%s" INFO_COPY_EXT, strZ(loadData->fileName));
MEM_CONTEXT_TEMP_BEGIN()
{
// Construct filename based on try
const String *const fileName = try == 0 ? loadData->fileName : strNewFmt("%s" INFO_COPY_EXT, strZ(loadData->fileName));

// Attempt to load the file
IoRead *read = storageReadIo(storageNewReadP(loadData->storage, fileName));
cipherBlockFilterGroupAdd(ioReadFilterGroup(read), loadData->cipherType, cipherModeDecrypt, loadData->cipherPass);
// Attempt to load the file
IoRead *const read = storageReadIo(storageNewReadP(loadData->storage, fileName));
cipherBlockFilterGroupAdd(ioReadFilterGroup(read), loadData->cipherType, cipherModeDecrypt, loadData->cipherPass);

MEM_CONTEXT_BEGIN(loadData->memContext)
{
loadData->infoBackup = infoBackupNewLoad(read);
result = true;
MEM_CONTEXT_BEGIN(loadData->memContext)
{
loadData->infoBackup = infoBackupNewLoad(read);
result = true;
}
MEM_CONTEXT_END();
}
MEM_CONTEXT_END();
MEM_CONTEXT_TEMP_END();
}

FUNCTION_LOG_RETURN(BOOL, result);
Expand Down
11 changes: 8 additions & 3 deletions src/info/infoPg.c
Expand Up @@ -374,7 +374,7 @@ infoPgSave(InfoPg *this, IoWrite *write, InfoSaveCallback *callbackFunction, voi

/**********************************************************************************************************************************/
String *
infoPgArchiveId(const InfoPg *this, unsigned int pgDataIdx)
infoPgArchiveId(const InfoPg *const this, const unsigned int pgDataIdx)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(INFO_PG, this);
Expand All @@ -383,9 +383,14 @@ infoPgArchiveId(const InfoPg *this, unsigned int pgDataIdx)

ASSERT(this != NULL);

InfoPgData pgData = infoPgData(this, pgDataIdx);
const InfoPgData pgData = infoPgData(this, pgDataIdx);
String *const version = pgVersionToStr(pgData.version);

FUNCTION_LOG_RETURN(STRING, strNewFmt("%s-%u", strZ(pgVersionToStr(pgData.version)), pgData.id));
String *const result = strNewFmt("%s-%u", strZ(version), pgData.id);

strFree(version);

FUNCTION_LOG_RETURN(STRING, result);
}

/**********************************************************************************************************************************/
Expand Down
28 changes: 16 additions & 12 deletions src/info/manifest.c
Expand Up @@ -2996,7 +2996,7 @@ typedef struct ManifestLoadFileData
} ManifestLoadFileData;

static bool
manifestLoadFileCallback(void *data, unsigned int try)
manifestLoadFileCallback(void *const data, const unsigned int try)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM_P(VOID, data);
Expand All @@ -3005,24 +3005,28 @@ manifestLoadFileCallback(void *data, unsigned int try)

ASSERT(data != NULL);

ManifestLoadFileData *loadData = (ManifestLoadFileData *)data;
ManifestLoadFileData *const loadData = data;
bool result = false;

if (try < 2)
{
// Construct filename based on try
const String *fileName = try == 0 ? loadData->fileName : strNewFmt("%s" INFO_COPY_EXT, strZ(loadData->fileName));
MEM_CONTEXT_TEMP_BEGIN()
{
// Construct filename based on try
const String *const fileName = try == 0 ? loadData->fileName : strNewFmt("%s" INFO_COPY_EXT, strZ(loadData->fileName));

// Attempt to load the file
IoRead *read = storageReadIo(storageNewReadP(loadData->storage, fileName));
cipherBlockFilterGroupAdd(ioReadFilterGroup(read), loadData->cipherType, cipherModeDecrypt, loadData->cipherPass);
// Attempt to load the file
IoRead *const read = storageReadIo(storageNewReadP(loadData->storage, fileName));
cipherBlockFilterGroupAdd(ioReadFilterGroup(read), loadData->cipherType, cipherModeDecrypt, loadData->cipherPass);

MEM_CONTEXT_BEGIN(loadData->memContext)
{
loadData->manifest = manifestNewLoad(read);
result = true;
MEM_CONTEXT_BEGIN(loadData->memContext)
{
loadData->manifest = manifestNewLoad(read);
result = true;
}
MEM_CONTEXT_END();
}
MEM_CONTEXT_END();
MEM_CONTEXT_TEMP_END();
}

FUNCTION_LOG_RETURN(BOOL, result);
Expand Down

0 comments on commit 78e912a

Please sign in to comment.