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 <[email protected]>
This commit is contained in:
@@ -142,9 +142,14 @@ BCollator::GetSortKey(const char* string, BString* key) const
|
|||||||
int requiredSize = fICUCollator->getSortKey(UnicodeString(string, length,
|
int requiredSize = fICUCollator->getSortKey(UnicodeString(string, length,
|
||||||
NULL, error), buffer, length * 2);
|
NULL, error), buffer, length * 2);
|
||||||
if (requiredSize > length * 2) {
|
if (requiredSize > length * 2) {
|
||||||
buffer = (uint8_t*)realloc(buffer, requiredSize);
|
uint8_t* tmpBuffer = (uint8_t*)realloc(buffer, requiredSize);
|
||||||
if (buffer == NULL)
|
if (tmpBuffer == NULL) {
|
||||||
|
free(buffer);
|
||||||
|
buffer = NULL;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
} else {
|
||||||
|
buffer = tmpBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
error = U_ZERO_ERROR;
|
error = U_ZERO_ERROR;
|
||||||
fICUCollator->getSortKey(UnicodeString(string, length, NULL, error),
|
fICUCollator->getSortKey(UnicodeString(string, length, NULL, error),
|
||||||
|
|||||||
Reference in New Issue
Block a user