Review Request 128016: [OS X] Prevent a crash in the IdealDockWidget's context menu

Tomaz Canabrava tcanabrava at kde.org
Thu May 26 10:47:38 UTC 2016


René,

But your code is not property written actually.

Foo *bar = new Foo() ;  *won't* return null on failure, it will throw an
std::bad_alloc, so your code is actually not doing anything, just a
pointless if, that will always succeed.

If you really, really wanna check for new failures, you must use a try /
catch idiom  or use new + nothrow.

But it's pointless. If there's not enough memory to create a object the
program shouldn't continue because it has not enough memory to work with.
Em 26 de mai de 2016 07:23, "René J.V. Bertin" <rjvbertin at gmail.com>
escreveu:

> This is an automatically generated e-mail. To reply, visit:
> https://git.reviewboard.kde.org/r/128016/
>
> On May 26th, 2016, 10:56 a.m. CEST, *Sven Brauch* wrote:
>
> sublime/idealdockwidget.cpp
> <https://git.reviewboard.kde.org/r/128016/diff/1/?file=465464#file465464line99> (Diff
> revision 1)
> 99
>
>     menu.addSection(windowIcon(), m_view->document()->title());
>
> 99
>
>     if (!menu) {
>
> Don't do this. It just clutters the code, and you would have to fix it in about every second line of the application anyways, should it ever happen (it doesn't on linux).
>
> On May 26th, 2016, 11:08 a.m. CEST, *René J.V. Bertin* wrote:
>
> I don't understand what you're implying here. Not doing this would either mean not using a pointer at all (= abandoning the patch), or not checking if the allocation succeeded. And that's not acceptable either. No matter how likely an application is to crash anyway if an allocation fails.
> From what I see this is true also when using a QScopedPointer.
>
> On May 26th, 2016, 11:46 a.m. CEST, *Sven Brauch* wrote:
>
> Nowhere in KDE code does anybody ever check if an allocation succeeds. IMO it's pedantic and useless. We are not writing life-critical software; if your system is out of memory, your IDE crashes, such is life. On Linux it doesn't do anything *anyways* in the default kernel configuration, since allocations always succeed.
>
> I just don't agree with that. If you really insist on not checking here, I'd propose that you remove the 2 lines in a separate commit, because I don't want to go on permanent record not doing things properly.
>
> Writing proper code is indeed pedantic. Is it useless? What's the percentage of security fixes that we would NOT see if everyone always checked against NULL before using a pointer?
>
> allocations always succeed.
>
> I'm not sure if I should be in awe for a kernel that apparently is able to provide more memory than I could ever afford to buy, or lose quite a bit of esteem for inciting lazy and sloppy programming practices...
>
>
> - René J.V.
>
> On May 25th, 2016, 10:54 p.m. CEST, René J.V. Bertin wrote:
> Review request for KDevelop.
> By René J.V. Bertin.
>
> *Updated May 25, 2016, 10:54 p.m.*
> *Repository: * kdevplatform
> Description
>
> OS X can be capricious when instances corresponding to a widget are deleted, if the class in question uses "native" ObjC SDKs behind the scenes. Pending events can in that case be (generated and) delivered to objects that were already deleted.
> According to the documentation, one should prefer to use QObject::deleteLater() rather than the regular, direct delete whether it be explicit or implicit.
>
> I've long used a local patch that uses this approach in order to prevent a recurring crash after using the context menu of the "ideal dock widget". Somehow I never put it up for review here, apparently.
>
> Testing
>
> Builds and permits reliable behaviour on both OS X and Linux.
>
> Diffs
>
>    - sublime/idealdockwidget.cpp (dae0ea2)
>
> View Diff <https://git.reviewboard.kde.org/r/128016/diff/>
>
> _______________________________________________
> KDevelop-devel mailing list
> KDevelop-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kdevelop-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20160526/6f8737fb/attachment-0001.html>


More information about the KDevelop-devel mailing list