[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: Not used QPointers showing modal dialogs via exec() - No crash
From: Thomas_Lübking <thomas.luebking () gmail ! com>
Date: 2013-11-12 13:36:47
Message-ID: 6412be6d-7802-4204-bde1-40a1b40f7e9d () gmail ! com
[Download RAW message or body]
On Dienstag, 12. November 2013 08:24:30 CEST, Harsh Kumar wrote:
> 1. If there is some code after exec() then code will crash as the
> QObject has been deleted.
As long as there's no reference to any (pot.) freed memory, code after the \
nested eventloop is in general no problem (ie. you can still put "int i = \
1; ++i;" etc. after the nested eventloop - no risk)
> 2. Even if there is no code after exec(), there can be a crash when
> stack is cleared while returning from the function.
> However, the problem is that here we are not seeing a crash. It seems
> the code can be potentially dangerous, but is not crashing in this
> case.
Notice that this case either implies:
a) a nested loop QObject on the stack (crashes when the parent \
deconstructor deletes it [1]) b) you leak the heap object
c) the nested heap object is local static or a member
I assume that the "quit" case gets special treatment (closing all windows \
in proper order first, thus exiting the nested loop before deleting the \
parenting window)
> 3. In any case, such nested eventloops should be avoided. But if used,
> then object must be created on heap & there should be appropriate
> checks before using the object to check if it is still valid.
Yes. And as mentioned: *any* pointed memory that could be deleted during \
the nested loop (in theory more or less any non local heap pointer and esp. \
"this" and QObject's) should be guarded.
Cheers,
Thomas
[1]
#include <stdio.h>
int main(int argc, char **argv)
{
int i = 1;
printf("a\n");
int *j = &i;
printf("b\n");
delete j; // this will crash - stack deletion is illegal
printf("c\n");
int k = i;
printf("%d\n", k);
}
> > Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to \
> > unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic