Skip to content

Commit

Permalink
Simplify calls of free
Browse files Browse the repository at this point in the history
It is not necessary to check for null pointers.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Nov 24, 2016
1 parent a8f4441 commit 6158f7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
15 changes: 6 additions & 9 deletions opencl/opencl_device_selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ static ds_status releaseDSProfile(ds_profile* profile, ds_score_release sr) {
if (profile->devices!=NULL && sr!=NULL) {
unsigned int i;
for (i = 0; i < profile->numDevices; i++) {
if (profile->devices[i].oclDeviceName)
free(profile->devices[i].oclDeviceName);
if (profile->devices[i].oclDriverVersion)
free(profile->devices[i].oclDriverVersion);
free(profile->devices[i].oclDeviceName);
free(profile->devices[i].oclDriverVersion);
status = sr(profile->devices[i].score);
if (status != DS_SUCCESS)
break;
Expand Down Expand Up @@ -171,15 +169,14 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
profile->version = version;

cleanup:
if (platforms) free(platforms);
if (devices) free(devices);
free(platforms);
free(devices);
if (status == DS_SUCCESS) {
*p = profile;
}
else {
if (profile) {
if (profile->devices)
free(profile->devices);
free(profile->devices);
free(profile);
}
}
Expand Down Expand Up @@ -585,7 +582,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
}
}
cleanup:
if (contentStart!=NULL) free(contentStart);
free(contentStart);
return status;
}

Expand Down
29 changes: 9 additions & 20 deletions opencl/openclwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,30 +538,19 @@ int OpenclDevice::GeneratBinFromKernelSource( cl_program program, const char * c
// Release all resouces and memory
for ( i = 0; i < numDevices; i++ )
{
if ( binaries[i] != NULL )
{
free( binaries[i] );
binaries[i] = NULL;
}
free(binaries[i]);
binaries[i] = NULL;
}

if ( binaries != NULL )
{
free( binaries );
binaries = NULL;
}
free( binaries );
binaries = NULL;

if ( binarySizes != NULL )
{
free( binarySizes );
binarySizes = NULL;
}
free(binarySizes);
binarySizes = NULL;

if ( mpArryDevsID != NULL )
{
free( mpArryDevsID );
mpArryDevsID = NULL;
}
free(mpArryDevsID);
mpArryDevsID = NULL;

return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion training/commontraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ CLUSTERER *SetUpForClustering(const FEATURE_DEFS_STRUCT &FeatureDefs,
}
CharID++;
}
if ( Sample != NULL ) free( Sample );
free( Sample );
return( Clusterer );

} /* SetUpForClustering */
Expand Down

0 comments on commit 6158f7e

Please sign in to comment.