From 971af42f6fc0bf321c1e55f4f0f33b22f6aa1306 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 16 Feb 2006 20:29:30 +0000 Subject: [PATCH] Fixed a memory leak (another)! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16437 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/BTextView/StyleBuffer.cpp | 3 +-- src/kits/interface/BTextView/TextView.cpp | 26 +++++++++----------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/kits/interface/BTextView/StyleBuffer.cpp b/src/kits/interface/BTextView/StyleBuffer.cpp index 4cb6685a64..366d86cb58 100644 --- a/src/kits/interface/BTextView/StyleBuffer.cpp +++ b/src/kits/interface/BTextView/StyleBuffer.cpp @@ -473,9 +473,8 @@ _BStyleBuffer_::operator[](int32 index) const run.style = fNullStyle; } else { STEStyleRunDesc* runDesc = fStyleRunDesc[index]; - const STEStyleRecord* record = fStyleRecord[runDesc->index]; run.offset = runDesc->offset; - run.style = record->style; + run.style = fStyleRecord[runDesc->index]->style; } return run; diff --git a/src/kits/interface/BTextView/TextView.cpp b/src/kits/interface/BTextView/TextView.cpp index 4b1be24ed8..95d22f7444 100644 --- a/src/kits/interface/BTextView/TextView.cpp +++ b/src/kits/interface/BTextView/TextView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2005, Haiku Inc. + * Copyright 2001-2006, Haiku Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -69,7 +69,7 @@ struct flattened_text_run { uint8 green; uint8 blue; uint8 alpha; /* 255 == opaque */ - uint16 _reserved_; /* 0 */ + uint16 _reserved_; /* 0 */ }; @@ -1642,24 +1642,22 @@ BTextView::SetRunArray(int32 startOffset, int32 endOffset, const text_run_array text_run_array * BTextView::RunArray(int32 startOffset, int32 endOffset, int32 *outSize) const { - CALLED(); - STEStyleRange* styleRange = fStyles->GetStyleRange(startOffset, endOffset - 1); if (styleRange == NULL) return NULL; - text_run_array *res = AllocRunArray(styleRange->count, outSize); - - if (!res) - return NULL; - - for (int32 i = 0; i < res->count; i++) { - res->runs[i].offset = styleRange->runs[i].offset; - res->runs[i].font = &styleRange->runs[i].style.font; - res->runs[i].color = styleRange->runs[i].style.color; + text_run_array *runArray = AllocRunArray(styleRange->count, outSize); + if (runArray != NULL) { + for (int32 i = 0; i < runArray->count; i++) { + runArray->runs[i].offset = styleRange->runs[i].offset; + runArray->runs[i].font = styleRange->runs[i].style.font; + runArray->runs[i].color = styleRange->runs[i].style.color; + } } - return res; + free(styleRange); + + return runArray; }