kits/locale: Fix PVS 495
Fix memory leak when realloc() fails. Change-Id: I9062bb177919805e9973c5afd6bc01f8fbb753b6 Reviewed-on: https://review.haiku-os.org/c/1016 Reviewed-by: Barrett17 <b.vitruvio@gmail.com>
This commit is contained in:
parent
f9c74ffa6f
commit
7db28d3803
@ -142,9 +142,14 @@ BCollator::GetSortKey(const char* string, BString* key) const
|
||||
int requiredSize = fICUCollator->getSortKey(UnicodeString(string, length,
|
||||
NULL, error), buffer, length * 2);
|
||||
if (requiredSize > length * 2) {
|
||||
buffer = (uint8_t*)realloc(buffer, requiredSize);
|
||||
if (buffer == NULL)
|
||||
uint8_t* tmpBuffer = (uint8_t*)realloc(buffer, requiredSize);
|
||||
if (tmpBuffer == NULL) {
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
return B_NO_MEMORY;
|
||||
} else {
|
||||
buffer = tmpBuffer;
|
||||
}
|
||||
|
||||
error = U_ZERO_ERROR;
|
||||
fICUCollator->getSortKey(UnicodeString(string, length, NULL, error),
|
||||
|
Loading…
Reference in New Issue
Block a user