Closed Bug 1757110 Opened 4 years ago Closed 4 years ago

Migrate new/delete to UniquePtr in nsTableFrame.cpp

Categories

(Core :: Layout: Tables, task)

task

Tracking

()

RESOLVED FIXED
100 Branch
Tracking Status
firefox100 --- fixed

People

(Reporter: dholbert, Assigned: dshin)

Details

Attachments

(3 external files)

(Filing this as a possible relatively-straightforward good-first-bug for new team members.)

nsTableFrame.cpp has several manual new/delete invocations. We should migrate those to use mozilla::UniquePtr to avoid the potential for leaks and double-free bugs.

In particular, I'm noticing the BCPaintBorderIterator class's member-var mBlockDirInfo, which we lazily-initialize and then delete in the destructor if it's non-null:
https://searchfox.org/mozilla-central/rev/73a8000b0c0eb527faef01ea17c6d2398622a386/layout/tables/nsTableFrame.cpp#5982-5984

This would make for a good first conversion-to-UniquePtr. And then after that, I'd suggest looking through that .cpp file for other explicit delete invocations for other possible conversion opportunities.

Assignee: nobody → dshin

For reference, here's the UniquePtr documentation which is pretty good - I'd skim this "Usage" section before getting started here:
https://searchfox.org/mozilla-central/rev/1c54648c082efdeb08cf6a5e3a8187e83f7549b9/mfbt/UniquePtr.h#94

(And if it's useful, here's a search for other UniquePtr usages in layout, for more sample-usage: https://searchfox.org/mozilla-central/search?q=UniquePtr&path=layout )

Also, I forgot to mention in comment 0: as part of this conversion, we should switch from new to the safer MakeUnique when allocating for the variables in question here, e.g. on this line:
https://searchfox.org/mozilla-central/rev/73a8000b0c0eb527faef01ea17c6d2398622a386/layout/tables/nsTableFrame.cpp#6253

See documentation on MakeUnique (and why it's preferred) here:
https://searchfox.org/mozilla-central/rev/1c54648c082efdeb08cf6a5e3a8187e83f7549b9/mfbt/UniquePtr.h#554

This patch may also be useful for reference, as an earlier place where I migrated some memory to be managed by UniquePtr:
https://phabricator.services.mozilla.com/D84463

Pushed by dholbert@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7e4579ca48e5 Refactor `BCPaintBorderIterator::mBlockDirInfo` to use `mozilla::UniquePtr` r=dholbert
Keywords: leave-open
Pushed by dholbert@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/3c5073b93115 Refactor `nsTableFrame::mCellMap, mTableLayoutStrategy` to use `mozilla::UniquePtr` r=dholbert https://hg.mozilla.org/integration/autoland/rev/dd81d58d9d5f Refactor `BCCorners::corners` and `BCCellBorders::borders` to use `mozilla::UniquePtr` r=dholbert
Keywords: leave-open
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 100 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: