Mail: fix memory leak on realloc
Fixes #9873 Change-Id: I274fc61359c34ada1088994f65f3d3c762297176 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2069 Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
parent
30de32ecb1
commit
c039c51d77
@ -1039,12 +1039,20 @@ TTextView::KeyDown(const char *key, int32 count)
|
||||
end++;
|
||||
Select(start, end);
|
||||
if (fYankBuffer) {
|
||||
fYankBuffer = (char *)realloc(fYankBuffer,
|
||||
char *result = (char *)realloc(fYankBuffer,
|
||||
strlen(fYankBuffer) + (end - start) + 1);
|
||||
if (result == NULL) {
|
||||
free(fYankBuffer);
|
||||
fYankBuffer = NULL;
|
||||
break;
|
||||
}
|
||||
fYankBuffer = result;
|
||||
GetText(start, end - start,
|
||||
&fYankBuffer[strlen(fYankBuffer)]);
|
||||
} else {
|
||||
fYankBuffer = (char *)malloc(end - start + 1);
|
||||
if (fYankBuffer == NULL)
|
||||
break;
|
||||
GetText(start, end - start, fYankBuffer);
|
||||
}
|
||||
Delete();
|
||||
@ -2469,8 +2477,9 @@ TTextView::Reader::Run(void *_this)
|
||||
eol += 2; // CR+LF belong to the line
|
||||
size_t length = eol - header;
|
||||
|
||||
buffer = (char *)realloc(buffer, length + 1);
|
||||
if (buffer == NULL)
|
||||
free(buffer);
|
||||
buffer = (char *)malloc(buffer, length + 1);
|
||||
if (buffer == NULL)
|
||||
goto done;
|
||||
|
||||
memcpy(buffer, header, length);
|
||||
@ -3092,17 +3101,14 @@ TTextView::AddQuote(int32 start, int32 finish)
|
||||
// add quote to this line
|
||||
int32 lineLength = index - lastLine + 1;
|
||||
|
||||
char* newTarget = (char *)realloc(target,
|
||||
char* result = (char *)realloc(target,
|
||||
targetLength + lineLength + quoteLength);
|
||||
if (newTarget == NULL) {
|
||||
// free the old buffer
|
||||
if (result == NULL) {
|
||||
free(target);
|
||||
target = NULL;
|
||||
free(text);
|
||||
return;
|
||||
} else {
|
||||
target = newTarget;
|
||||
}
|
||||
target = result;
|
||||
|
||||
// copy the quote sign
|
||||
memcpy(&target[targetLength], QUOTE, quoteLength);
|
||||
|
Loading…
Reference in New Issue
Block a user