mail: Fix potential memory leak

Fix memory leak when realloc() failed.
Pointed out by Clang Static Analyzer.

Change-Id: I13f758c4d89275651e22785652d0880a6d5b1a8e
Reviewed-on: https://review.haiku-os.org/c/1064
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Murai Takashi
2019-02-19 18:31:44 +00:00
committed by waddlesplash
parent d938c7118f
commit a31244d098
+8 -3
View File
@@ -3090,11 +3090,16 @@ TTextView::AddQuote(int32 start, int32 finish)
// add quote to this line
int32 lineLength = index - lastLine + 1;
target = (char *)realloc(target, targetLength + lineLength + quoteLength);
if (target == NULL) {
// free the old buffer?
char* newTarget = (char *)realloc(target,
targetLength + lineLength + quoteLength);
if (newTarget == NULL) {
// free the old buffer
free(target);
target = NULL;
free(text);
return;
} else {
target = newTarget;
}
// copy the quote sign