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
This commit is contained in:
@@ -2673,6 +2673,21 @@ BTextView::UnflattenRunArray(const void *data, int32 *outSize)
|
|||||||
for (int32 i = 0; i < array->count; i++) {
|
for (int32 i = 0; i < array->count; i++) {
|
||||||
run_array->runs[i].offset = array->styles[i].offset;
|
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 = new BFont;
|
||||||
run_array->runs[i].font.SetFamilyAndStyle(array->styles[i].family,
|
run_array->runs[i].font.SetFamilyAndStyle(array->styles[i].family,
|
||||||
array->styles[i].style);
|
array->styles[i].style);
|
||||||
|
|||||||
Reference in New Issue
Block a user