From d81069bfad9e9bd8d3ddc75e8733bc9850e781ca Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Thu, 2 Feb 2006 08:52:07 +0000 Subject: [PATCH] Waldemar made me notice this leak. Adding a comment as I can't test the changes now. I'd like some comments on this problem as it isn't a minor one, especially if we add a BFont destructor in the future. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16195 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/BTextView/TextView.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/kits/interface/BTextView/TextView.cpp b/src/kits/interface/BTextView/TextView.cpp index 52882649bd..2c67e20bb5 100644 --- a/src/kits/interface/BTextView/TextView.cpp +++ b/src/kits/interface/BTextView/TextView.cpp @@ -2673,6 +2673,21 @@ BTextView::UnflattenRunArray(const void *data, int32 *outSize) for (int32 i = 0; i < array->count; i++) { run_array->runs[i].offset = array->styles[i].offset; + // TODO: Here we are leaking memory. + // We should use placement new instead + // new (&run_array->runs[i].font) BFont(); + // The reason we're calling the constructor explicitly is + // that the text_run_array() is allocated with malloc. It can't + // be allocated with new due to its nature: see its definition + // on the top of TextView.h + + // Note that BFont doesn't have a destructor. + // If it had one, our whole RunArray()/SetRunArray() api + // would have to be changed, as it doesn't fit with the fact + // that we'd have to call the BFont's destructor. Or, as Waldemar + // suggested, we'd have to provide a "free_text_run_array()" method + // which would take care of calling the destructors. + run_array->runs[i].font = new BFont; run_array->runs[i].font.SetFamilyAndStyle(array->styles[i].family, array->styles[i].style);