Skip to content

Commit

Permalink
OpenCL: Fix alloc-dealloc mismatch
Browse files Browse the repository at this point in the history
Bug message from AddressSanitizer:

    ==7153==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs free) on 0x602000072cb0
        #0 0x7ffff70c6a10 in free (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1a10)
        #1 0x555557188638 in writeProfileToFile ../../../../../src/opencl/openclwrapper.cpp:541

Signed-off-by: Stefan Weil <[email protected]>
stweil committed Jan 19, 2019
1 parent ad19183 commit 66e31bf
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/opencl/openclwrapper.cpp
Original file line number Diff line number Diff line change
@@ -289,7 +289,7 @@ static ds_status readProFile(const char* fileName, char** content,
}

typedef ds_status (*ds_score_deserializer)(ds_device* device,
const unsigned char* serializedScore,
const uint8_t* serializedScore,
unsigned int serializedScoreSize);

static ds_status readProfileFromFile(ds_profile* profile,
@@ -465,7 +465,7 @@ static ds_status readProfileFromFile(ds_profile* profile,
}

typedef ds_status (*ds_score_serializer)(ds_device* device,
void** serializedScore,
uint8_t** serializedScore,
unsigned int* serializedScoreSize);
static ds_status writeProfileToFile(ds_profile* profile,
ds_score_serializer serializer,
@@ -489,7 +489,7 @@ static ds_status writeProfileToFile(ds_profile* profile,
fwrite("\n", sizeof(char), 1, profileFile);

for (i = 0; i < profile->numDevices && status == DS_SUCCESS; i++) {
void* serializedScore;
uint8_t* serializedScore;
unsigned int serializedScoreSize;

fwrite(DS_TAG_DEVICE, sizeof(char), strlen(DS_TAG_DEVICE), profileFile);
@@ -538,7 +538,7 @@ static ds_status writeProfileToFile(ds_profile* profile,
if (status == DS_SUCCESS && serializedScore != nullptr &&
serializedScoreSize > 0) {
fwrite(serializedScore, sizeof(char), serializedScoreSize, profileFile);
free(serializedScore);
delete[] serializedScore;
}
fwrite(DS_TAG_SCORE_END, sizeof(char), strlen(DS_TAG_SCORE_END),
profileFile);
@@ -2409,17 +2409,17 @@ static double getLineMasksMorphMicroBench(GPUEnv* env,
#include <cstdlib>

// encode score object as byte string
static ds_status serializeScore(ds_device* device, void** serializedScore,
static ds_status serializeScore(ds_device* device, uint8_t** serializedScore,
unsigned int* serializedScoreSize) {
*serializedScoreSize = sizeof(TessDeviceScore);
*serializedScore = new unsigned char[*serializedScoreSize];
*serializedScore = new uint8_t[*serializedScoreSize];
memcpy(*serializedScore, device->score, *serializedScoreSize);
return DS_SUCCESS;
}

// parses byte string and stores in score object
static ds_status deserializeScore(ds_device* device,
const unsigned char* serializedScore,
const uint8_t* serializedScore,
unsigned int serializedScoreSize) {
// check that serializedScoreSize == sizeof(TessDeviceScore);
device->score = new TessDeviceScore;

0 comments on commit 66e31bf

Please sign in to comment.