Bug 107880 - Use ScopedVclPtrInstance where possible
Summary: Use ScopedVclPtrInstance where possible
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:6.0.0
Keywords: difficultyBeginner, easyHack, skillCpp
Depends on:
Blocks:
 
Reported: 2017-05-15 21:38 UTC by Markus Mohrhard
Modified: 2017-08-28 12:10 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Mohrhard 2017-05-15 21:38:43 UTC
Currently we have many methods that do an explicit:

VclPtr<VirtualDevice> aDev = VclPtr<VirtualDevice>::Create(...);
....
aDev.disposeAndClear();


This construct is not exception safe and can easily introduce GDI leaks with new return paths. For these cases we actually have ScopedVclPtrInstance which automatically calls dispose when the object out of scope.

This task is about going through the list returned by git grep VclPtr<VirtualDevice>::Create and transform the ones that call the disposeAndClear inside of the same method to a ScopedVclPtrInstance.

An example that shows where this can be done is https://cgit.freedesktop.org/libreoffice/core/tree/sw/source/core/view/viewsh.cxx?id=509c91aca5a9e89e9453082486ac7d67f649a7f5#n329

All the other places need to be checked if this works there as well.
Comment 1 Commit Notification 2017-06-28 07:21:26 UTC
Christian Barth committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=89494fc501142f83a4ae387394d939d25252f796

tdf#107880: Make use of ScopedVclPtr

It will be available in 6.0.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 2 Chris 2017-06-28 17:14:19 UTC
Seems like this is the only place to do this. The most of the other occurrences are class members with destruction in DTOR.
Comment 3 Ekansh Jha 2017-08-03 12:28:58 UTC
I want to work on this issue, want to know if it's still open.
Comment 4 Shinnok 2017-08-14 11:28:55 UTC
@Markus can you please provide your feedback on this? I briefly check that myself and there doesn't seem to be much to be done on this one.
Comment 5 Shinnok 2017-08-28 12:10:44 UTC
This change has been merged in https://gerrit.libreoffice.org/#/c/39321/ .