[Kst] kdeextragear-2/kst/kst

George Staikos staikos at kde.org
Tue Jul 27 00:36:28 CEST 2004

On Monday 26 July 2004 18:19, Andrew Walker wrote:
> CVS commit by arwalker:
> With the advent of Linux being able to function as a memory manager and not
> just an address space manager this kind of memory check is no longer
> pointless. George, I'd appreciate if you'd leave these kind of checks alone
> - which I believe is the decision that we arrived with Barth some time ago.

   You are missing the point here.  The big allocations of primitive blocks 
are perfectly fine to check, especially since they use malloc().  QObjects 
are not.  No matter what you do, you cannot, ever, prevent such a crash on 
OOM with Qt based applications.  The best you could possibly do is catch an 
exception and exit() immediately.  Even checking for null is futile since it 
is equally likely that any internal malloc (Qt does very many!) could fail 
instead of the first one.  I discussed this with various people from 
Trolltech recently.  I also saw slides from them about the number of mallocs 
that are done implicitly in various classes.  It's huge.  (Qt4 fixes this, 
but there are always still internal mallocs.)  

   In this specific case, in most or all of the call sequences, Kst will still 
be guaranteed to crash because of following calls.  See kstfitdialog around 
line 266.  KstSharedPtr<Plugin> pPtr = PluginCollection::self()->.....

    That line will most likely crash.  If not, you've got a big collection of 
them following.  Note that QString() construction and various other QString 
operations used here cause multiple mallocs.

   Putting objects on the stack is insufficient - almost all of them put 
something on the heap in their constructor.

   In the end, adding if() around QObject mallocs is:
- pointless, since it never returns 0  (the C++ Working Paper requires that 
"new" never return a null pointer)
- ugly and cluttering up the code
- adding unnecessary branches
- doomed to fail even if it did return 0

> --- kdeextragear-2/kst/kst/kstfitdialog_i.cpp  #1.25:1.26
> @@ -736,7 +736,9 @@ void KstFitDialogI::pluginChanged(int id
>  void KstFitDialogI::showPluginManager() {
>    PluginManager *pm = new PluginManager(this, "Plugin Manager");
> +  if (pm) {
>    pm->exec();
>    delete pm;
>    updatePluginList();
> +  }
>  }

George Staikos
KDE Developer			http://www.kde.org/
Staikos Computing Services Inc.	http://www.staikos.net/

More information about the Kst mailing list