Skip to content

Commit

Permalink
Try to fix "-fsanitize=address" error: "ERROR: AddressSanitizer: allo…
Browse files Browse the repository at this point in the history
…c-dealloc-mismatch (malloc vs operator delete [])"
  • Loading branch information
s-trinh committed Jan 23, 2024
1 parent a33c08c commit 9a6bbcf
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions modules/io/src/image/private/vpImageIoStb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ void readPNGfromMemStb(const std::vector<unsigned char> &buffer, vpImage<unsigne
unsigned char *buffer_read = stbi_load_from_memory(buffer.data(), buffer.size(), &x, &y, &comp, req_channels);
assert(comp == req_channels);

// I = vpImage<unsigned char>(buffer_read, y, x, true);
I.init(buffer_read, y, x, true);
delete[] buffer_read;
STBI_FREE(buffer_read);
}

/*!
Expand All @@ -178,12 +177,12 @@ void readPNGfromMemStb(const std::vector<unsigned char> &buffer, vpImage<vpRGBa>
vpImageConvert::RGBToRGBa(buffer_read, reinterpret_cast<unsigned char *>(I_color.bitmap), x, y, flip);
}
else {
delete[] buffer_read;
STBI_FREE(buffer_read);
std::string message = "Wrong number of channels for the input buffer: " + std::to_string(comp);
throw(vpImageException(vpImageException::ioError, message));
}

delete[] buffer_read;
STBI_FREE(buffer_read);
}

/*!
Expand Down

0 comments on commit 9a6bbcf

Please sign in to comment.