Skip to content

Commit

Permalink
fix code scan reported errors - dead code, unreachable code, unnecess…
Browse files Browse the repository at this point in the history
…ary free etc
  • Loading branch information
Priyesh Padmavilasom committed Mar 31, 2016
1 parent 6a8a62e commit ecb49ed
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 89 deletions.
18 changes: 9 additions & 9 deletions client/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ TDNFCheckLocalPackages(
pszRPMPath = g_build_filename(pszLocalPath, pszFile, NULL);
hPkg = hy_sack_add_cmdline_package(hSack, pszRPMPath);

g_free(pszRPMPath);
pszRPMPath = NULL;

if(!hPkg)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
hy_packagelist_push(hPkgList, hPkg);
hPkg = NULL;

g_free(pszRPMPath);
pszRPMPath = NULL;
}

fprintf(stdout, "Found %d packages\n", hy_packagelist_count(hPkgList));
Expand Down Expand Up @@ -1023,13 +1023,13 @@ TDNFFreeCmdArgs(
TDNF_SAFE_FREE_MEMORY(pCmdArgs->ppszCmds[nIndex]);
}
TDNF_SAFE_FREE_MEMORY(pCmdArgs->ppszCmds);
}
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszInstallRoot);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszConfFile);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszReleaseVer);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszInstallRoot);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszConfFile);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pszReleaseVer);

TDNF_SAFE_FREE_MEMORY(pCmdArgs->pSetOpt);
TDNF_SAFE_FREE_MEMORY(pCmdArgs);
TDNF_SAFE_FREE_MEMORY(pCmdArgs->pSetOpt);
TDNF_SAFE_FREE_MEMORY(pCmdArgs);
}
}

const char*
Expand Down
2 changes: 1 addition & 1 deletion client/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ TDNFCopyEnabledRepos(
return dwError;

error:
if(!pppszReposUsed)
if(pppszReposUsed)
{
*pppszReposUsed = NULL;
}
Expand Down
14 changes: 12 additions & 2 deletions client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ TDNFApplyPackageFilter(
)
{
uint32_t dwError = 0;
int nCmpType = HY_GLOB;

if(!hQuery || !ppszPackageNameSpecs)
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
Expand All @@ -92,12 +94,20 @@ TDNFApplyPackageFilter(
{
if(TDNFIsGlob(*ppszPackageNameSpecs))
{
hy_query_filter(hQuery, HY_PKG_NAME, HY_GLOB, *ppszPackageNameSpecs);
nCmpType = HY_GLOB;
}
else
{
hy_query_filter(hQuery, HY_PKG_NAME, HY_EQ, *ppszPackageNameSpecs);
nCmpType = HY_EQ;
}

dwError = hy_query_filter(
hQuery,
HY_PKG_NAME,
nCmpType,
*ppszPackageNameSpecs);
BAIL_ON_TDNF_HAWKEY_ERROR(dwError);

++ppszPackageNameSpecs;
}

Expand Down
5 changes: 0 additions & 5 deletions client/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ TDNFReadConfig(
uint32_t dwError = 0;

GKeyFile* pKeyFile = NULL;
char* pszValue = NULL;

PTDNF_CONF pConf = NULL;

Expand Down Expand Up @@ -174,10 +173,6 @@ TDNFReadConfig(
{
g_key_file_free(pKeyFile);
}
if(pszValue)
{
g_free(pszValue);
}
return dwError;

error:
Expand Down
78 changes: 47 additions & 31 deletions client/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,51 +37,67 @@ typedef enum
#define IsNullOrEmptyString(str) (!(str) || !(*str))

#define BAIL_ON_TDNF_ERROR(dwError) \
if (dwError) \
{ \
goto error; \
}
do { \
if (dwError) \
{ \
goto error; \
} \
} while(0)

#define BAIL_ON_TDNF_SYSTEM_ERROR(dwError) \
if (dwError) \
{ \
dwError = ERROR_TDNF_SYSTEM_BASE + dwError; \
goto error; \
}
do { \
if (dwError) \
{ \
dwError = ERROR_TDNF_SYSTEM_BASE + dwError; \
goto error; \
} \
} while(0)

#define BAIL_ON_TDNF_HAWKEY_ERROR(dwError) \
if (dwError) \
{ \
dwError = ERROR_TDNF_HAWKEY_BASE + dwError; \
goto error; \
}
do { \
if (dwError) \
{ \
dwError = ERROR_TDNF_HAWKEY_BASE + dwError; \
goto error; \
} \
} while(0)

#define BAIL_ON_TDNF_RPM_ERROR(dwError) \
if (dwError) \
{ \
dwError = ERROR_TDNF_RPM_BASE + dwError; \
goto error; \
}
do { \
if (dwError) \
{ \
dwError = ERROR_TDNF_RPM_BASE + dwError; \
goto error; \
} \
} while(0)

#define TDNF_SAFE_FREE_MEMORY(pMemory) \
if (pMemory) { \
TDNFFreeMemory(pMemory); \
}
do { \
if (pMemory) { \
TDNFFreeMemory(pMemory); \
} \
} while(0)

#define TDNF_SAFE_FREE_PKGLIST(hPkgList) \
if (hPkgList) { \
hy_packagelist_free(hPkgList); \
}
do { \
if (hPkgList) { \
hy_packagelist_free(hPkgList); \
} \
} while(0)

#define TDNF_SAFE_FREE_STRINGARRAY(ppArray) \
if (ppArray) { \
TDNFFreeStringArray(ppArray); \
}
do { \
if (ppArray) { \
TDNFFreeStringArray(ppArray); \
} \
} while(0)

#define TDNF_SAFE_FREE_PKGINFO(pPkgInfo) \
if (pPkgInfo) { \
TDNFFreePackageInfo(pPkgInfo); \
}
do { \
if (pPkgInfo) { \
TDNFFreePackageInfo(pPkgInfo); \
} \
} while(0)
//Misc
#define TDNF_RPM_EXT ".rpm"

Expand Down
4 changes: 0 additions & 4 deletions client/goal.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ TDNFGoalReportProblems(
}
}
cleanup:
if(pszProblem)
{
hy_free(pszProblem);
}
return dwError;

error:
Expand Down
20 changes: 0 additions & 20 deletions client/packageutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ TDNFFindAvailablePkgByPkg(
{
*phPkg = NULL;
}
if(hPkg)
{
hy_package_free(hPkg);
}
goto cleanup;
}

Expand Down Expand Up @@ -205,10 +201,6 @@ TDNFFindInstalledPkgByName(
{
*phPkg = NULL;
}
if(hPkg)
{
hy_package_free(hPkg);
}
goto cleanup;
}

Expand Down Expand Up @@ -258,10 +250,6 @@ TDNFGetInstalled(
{
*phPkgList = NULL;
}
if(hPkgList)
{
hy_packagelist_free(hPkgList);
}
if(hQuery)
{
hy_query_free(hQuery);
Expand Down Expand Up @@ -315,10 +303,6 @@ TDNFMatchForReinstall(
{
*phPkgList = NULL;
}
if(hPkgList)
{
hy_packagelist_free(hPkgList);
}
if(hPkgAvailable)
{
hy_package_free(hPkgAvailable);
Expand Down Expand Up @@ -879,10 +863,6 @@ TDNFFilterPackages(
{
*phPkgList = NULL;
}
if(hPkgList)
{
hy_packagelist_free(hPkgList);
}
goto cleanup;
}

Expand Down
1 change: 1 addition & 0 deletions client/remoterepo.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ TDNFDownloadPackage(
fprintf(stdout, "\n");
cleanup:
TDNF_SAFE_FREE_MEMORY(pszBaseUrl);
TDNF_SAFE_FREE_MEMORY(pszUserPass);
if(pRepoHandle)
{
lr_handle_free(pRepoHandle);
Expand Down
19 changes: 12 additions & 7 deletions client/repoutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ TDNFRepoRemoveCache(
char* pszFilePath = NULL;
GDir* pDir = NULL;

if(!pTdnf || IsNullOrEmptyString(pszRepoId))
if(!pTdnf || !pTdnf->pConf || IsNullOrEmptyString(pszRepoId))
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
Expand Down Expand Up @@ -233,17 +233,22 @@ TDNFRepoRemoveCache(
while ((pszFile = g_dir_read_name (pDir)) != NULL)
{
pszFilePath = g_build_filename(pszRepoCacheDir, pszFile, NULL);

if(unlink(pszFilePath))
{
dwError = errno;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}
if(pszFilePath)
{
if(unlink(pszFilePath))
{
dwError = errno;
BAIL_ON_TDNF_SYSTEM_ERROR(dwError);
}

g_free(pszFilePath);
pszFilePath = NULL;
}
else
{
dwError = ERROR_TDNF_INVALID_PARAMETER;
BAIL_ON_TDNF_ERROR(dwError);
}
}
if(rmdir(pszRepoCacheDir))
{
Expand Down
5 changes: 5 additions & 0 deletions client/updateinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ TDNFFreeUpdateInfo(

TDNFFreeUpdateInfoReferences(pUpdateInfo->pReferences);
TDNFFreeUpdateInfoPackages(pUpdateInfo->pPackages);
TDNF_SAFE_FREE_MEMORY(pUpdateInfo);
}
}

Expand Down Expand Up @@ -255,6 +256,10 @@ TDNFGetUpdateInfoPackages(
{
*ppPkgs = NULL;
}
if(pPkg)
{
TDNFFreeUpdateInfoPackages(pPkg);
}
if(pPkgs)
{
TDNFFreeUpdateInfoPackages(pPkgs);
Expand Down
29 changes: 19 additions & 10 deletions tools/cli/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,29 @@
#define IsNullOrEmptyString(str) (!(str) || !(*str))

#define BAIL_ON_CLI_ERROR(unError) \
if (unError) \
{ \
goto error; \
}
do { \
if (unError) \
{ \
goto error; \
} \
} \
while(0)

#define TDNF_CLI_SAFE_FREE_MEMORY(pMemory) \
if (pMemory) { \
TDNFFreeMemory(pMemory); \
}
do { \
if (pMemory) { \
TDNFFreeMemory(pMemory); \
} \
} \
while(0)

#define TDNF_CLI_SAFE_FREE_STRINGARRAY(ppArray) \
if (ppArray) { \
TDNFFreeStringArray(ppArray); \
}
do { \
if (ppArray) { \
TDNFFreeStringArray(ppArray); \
} \
} \
while(0)

typedef uint32_t (*PFN_CMD)(PTDNF, PTDNF_CMD_ARGS);

Expand Down

0 comments on commit ecb49ed

Please sign in to comment.