Skip to content

Commit 6158f7e

Browse files
committed
Simplify calls of free
It is not necessary to check for null pointers. Signed-off-by: Stefan Weil <[email protected]>
1 parent a8f4441 commit 6158f7e

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

opencl/opencl_device_selection.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ static ds_status releaseDSProfile(ds_profile* profile, ds_score_release sr) {
7272
if (profile->devices!=NULL && sr!=NULL) {
7373
unsigned int i;
7474
for (i = 0; i < profile->numDevices; i++) {
75-
if (profile->devices[i].oclDeviceName)
76-
free(profile->devices[i].oclDeviceName);
77-
if (profile->devices[i].oclDriverVersion)
78-
free(profile->devices[i].oclDriverVersion);
75+
free(profile->devices[i].oclDeviceName);
76+
free(profile->devices[i].oclDriverVersion);
7977
status = sr(profile->devices[i].score);
8078
if (status != DS_SUCCESS)
8179
break;
@@ -171,15 +169,14 @@ static ds_status initDSProfile(ds_profile** p, const char* version) {
171169
profile->version = version;
172170

173171
cleanup:
174-
if (platforms) free(platforms);
175-
if (devices) free(devices);
172+
free(platforms);
173+
free(devices);
176174
if (status == DS_SUCCESS) {
177175
*p = profile;
178176
}
179177
else {
180178
if (profile) {
181-
if (profile->devices)
182-
free(profile->devices);
179+
free(profile->devices);
183180
free(profile);
184181
}
185182
}
@@ -585,7 +582,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
585582
}
586583
}
587584
cleanup:
588-
if (contentStart!=NULL) free(contentStart);
585+
free(contentStart);
589586
return status;
590587
}
591588

opencl/openclwrapper.cpp

+9-20
Original file line numberDiff line numberDiff line change
@@ -538,30 +538,19 @@ int OpenclDevice::GeneratBinFromKernelSource( cl_program program, const char * c
538538
// Release all resouces and memory
539539
for ( i = 0; i < numDevices; i++ )
540540
{
541-
if ( binaries[i] != NULL )
542-
{
543-
free( binaries[i] );
544-
binaries[i] = NULL;
545-
}
541+
free(binaries[i]);
542+
binaries[i] = NULL;
546543
}
547544

548-
if ( binaries != NULL )
549-
{
550-
free( binaries );
551-
binaries = NULL;
552-
}
545+
free( binaries );
546+
binaries = NULL;
553547

554-
if ( binarySizes != NULL )
555-
{
556-
free( binarySizes );
557-
binarySizes = NULL;
558-
}
548+
free(binarySizes);
549+
binarySizes = NULL;
559550

560-
if ( mpArryDevsID != NULL )
561-
{
562-
free( mpArryDevsID );
563-
mpArryDevsID = NULL;
564-
}
551+
free(mpArryDevsID);
552+
mpArryDevsID = NULL;
553+
565554
return 1;
566555
}
567556

training/commontraining.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ CLUSTERER *SetUpForClustering(const FEATURE_DEFS_STRUCT &FeatureDefs,
524524
}
525525
CharID++;
526526
}
527-
if ( Sample != NULL ) free( Sample );
527+
free( Sample );
528528
return( Clusterer );
529529

530530
} /* SetUpForClustering */

0 commit comments

Comments
 (0)