[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Sat Jun 5 19:01:39 CEST 2004


CVS commit by arwalker: 

I have reverted the reversions. The change I made was correct.

The problem was that KstSharedPtr was not checking the correct
values for the deletion of an object. As a result once any
KstSharedPtr object was created it was never destroyed.

You can confirm this by placing a breakpoint on the destructor
of objects like KstVCurve. The execution will never break there.
Also, if you watch the data manager, the reference count on 
vectors will never go down, even when you delete the curves that
use them.

Fixing the problem in KstSharedPtr exposed other memory problems,
hence the crashes. I've fixed one major problem, but there may be
others left to be found. Now that objects are actually getting 
deleted previously hidden problems are emerging.


  M +18 -15    curveplacementwidget.ui.h   1.5
  M +3 -14     kstdoc.cpp   1.82
  M +1 -3      kstsharedptr.h   1.5
  M +0 -3      ksttoplevelview.h   1.31
  M +6 -1      kstviewwindow.cpp   1.9
  M +1 -1      kstviewwindow.h   1.9


--- kdeextragear-2/kst/kst/curveplacementwidget.ui.h  #1.4:1.5
@@ -88,9 +88,12 @@ void CurvePlacementWidget::updatePlotLis
         Kst2DPlotList plots = static_cast<KstViewWindow*>(c)->view()->findChildrenType<Kst2DPlot>();
 
-        for (Kst2DPlotList::Iterator i = plots.begin(); i != plots.end(); ++i) {
+    Kst2DPlotList::Iterator i = plots.begin();
+    if (i != plots.end()) {
+      for ( ; i != plots.end(); ++i) {
             _plotList->insertItem((*i)->tagName());
         }
+    }
 
-        if (!old.isNull() && _plotList->count()) {
+    if (!old.isNull() && _plotList->count() > 0) {
             _plotList->setCurrentText(old);
         }

--- kdeextragear-2/kst/kst/kstdoc.cpp  #1.81:1.82
@@ -466,6 +466,4 @@ bool KstDoc::saveDocument(const QString 
 
 void KstDoc::deleteContents() {
-  KMdiIterator<KMdiChildView*>* pIterator;
-
   KST::vectorDefaults.sync();
 
@@ -475,15 +473,5 @@ void KstDoc::deleteContents() {
 
   if (KstApp::inst()) {
-    pIterator = KstApp::inst()->createIterator();
-    if (pIterator) {
-      while (pIterator->currentItem()) {
-        KMdiChildView *pView = pIterator->currentItem();
-        pIterator->next();
-        if (pView) {
-          KstApp::inst()->closeWindow(pView);
-        }
-      }
-      KstApp::inst()->deleteIterator(pIterator);
-    }
+    KstApp::inst()->closeAllViews();
   }
   
@@ -859,6 +847,7 @@ static bool backupFile(const QString& qF
     ::close( fd );
 
-    if (::close(fd2))
+    if (::close(fd2)) {
         return false;
+    }
     return true;
 }

--- kdeextragear-2/kst/kst/kstsharedptr.h  #1.4:1.5
@@ -52,7 +52,5 @@ public:
     * the count goes to 0, this object will delete itself.
     */
-   // THE COMMENTED LINE BELOW CAUSED IMPRESSIVE CRASH.  Reverted for now... Andrew?
-   //void _KShared_unref() const { sem--;  if (sem.total() == sem.available()) delete this; }
-   void _KShared_unref() const { sem--;  if (sem.total() == 0) delete this; }
+   void _KShared_unref() const { sem--;  if (sem.total() == sem.available()) delete this; }
 
    /**

--- kdeextragear-2/kst/kst/ksttoplevelview.h  #1.30:1.31
@@ -112,7 +112,4 @@ class KstTopLevelView : public KstViewOb
 };
 
-typedef KstSharedPtr<KstTopLevelView> KstTopLevelViewPtr;
-typedef KstObjectList<KstTopLevelViewPtr> KstTopLevelViewList;
-
 template<class T>
 KstSharedPtr<T> KstTopLevelView::createPlot(const QString& name) {

--- kdeextragear-2/kst/kst/kstviewwindow.cpp  #1.8:1.9
@@ -60,4 +60,5 @@ KstViewWindow::KstViewWindow(QWidget *pa
   commonConstructor();
   _view = new KstTopLevelView(this);
+  _view->_KShared_ref();
 }
 
@@ -71,4 +72,5 @@ KstViewWindow::KstViewWindow(QDomElement
   commonConstructor();
   _view = new KstTopLevelView(e, this);
+  _view->_KShared_ref();
 
   QDomNode n = e.firstChild();
@@ -123,4 +125,7 @@ void KstViewWindow::updateActions() {
 
 KstViewWindow::~KstViewWindow() {
+  if (_view) {
+    _view->_KShared_unref();
+  }
 }
 
@@ -271,5 +276,5 @@ void KstViewWindow::save(QTextStream& ts
 }
 
-KstTopLevelViewPtr KstViewWindow::view() const {
+KstTopLevelView* KstViewWindow::view() const {
   return _view;
 }

--- kdeextragear-2/kst/kst/kstviewwindow.h  #1.8:1.9
@@ -49,5 +49,5 @@ class KstViewWindow : public KMdiChildVi
     void togglePaused();
     void save(QTextStream& ts);
-    KstTopLevelViewPtr view() const;
+    KstTopLevelView* view() const;
 
   protected:





More information about the Kst mailing list