Fix memory leaks in printer manufacturer lists
authorsherscher@apple.com <sherscher@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Wed, 28 Oct 2009 18:21:01 +0000 (18:21 +0000)
committersherscher@apple.com <sherscher@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Wed, 28 Oct 2009 18:21:01 +0000 (18:21 +0000)
git-svn-id: http://svn.macosforge.org/repository/mDNSResponder/trunk@6757 214c2c4a-bf3b-4dcf-9390-e4dd3010487d

Clients/PrinterSetupWizard/ThirdPage.cpp
Clients/PrinterSetupWizard/ThirdPage.h

index 069e559..1d49523 100644 (file)
@@ -139,32 +139,27 @@ exit:
        return;
 }
 
-CThirdPage::~CThirdPage()
+
+void
+CThirdPage::FreeManufacturers( Manufacturers & manufacturers )
 {
-       //
-       // clean up all the printer manufacturers
-       //
-       while (m_manufacturers.size())
+       for ( Manufacturers::iterator it = manufacturers.begin(); it != manufacturers.end(); it++ )
        {
-               Manufacturers::iterator iter = m_manufacturers.begin();
-
-               while (iter->second->models.size())
+               for ( Models::iterator it2 = it->second->models.begin(); it2 != it->second->models.end(); it2++ )
                {
-                       Models::iterator it = iter->second->models.begin();
-
-                       Model * model = *it;
-
-                       delete model;
-
-                       iter->second->models.erase(it);
+                       delete *it2;
                }
 
-               delete iter->second;
-
-               m_manufacturers.erase(iter);
+               delete it->second;
        }
 }
 
+
+CThirdPage::~CThirdPage()
+{
+       FreeManufacturers( m_manufacturers );
+}
+
 // ----------------------------------------------------
 // SelectMatch
 //
@@ -993,6 +988,8 @@ OSStatus CThirdPage::MatchPrinter(Manufacturers & manufacturers, Printer * print
                                LoadGenericPrintDriverDefs( genericManufacturers );
 
                                SelectMatch( genericManufacturers, printer, service, genericManufacturer, genericModel );
+
+                               FreeManufacturers( genericManufacturers );
                        }
                        else
                        {
@@ -1026,6 +1023,8 @@ OSStatus CThirdPage::MatchPrinter(Manufacturers & manufacturers, Printer * print
                        SelectMatch( genericManufacturers, printer, service, genericManufacturer, genericModel );
                        
                        text.LoadString(IDS_PRINTER_MATCH_GOOD);
+
+                       FreeManufacturers( genericManufacturers );
                }
                else
                {
@@ -1562,6 +1561,7 @@ void CThirdPage::OnBnClickedHaveDisk()
 
 exit:
 
+       FreeManufacturers( manufacturers );
        return;
 }
 
index c726eb4..63ad256 100644 (file)
@@ -124,6 +124,8 @@ private:
        //
        void                            AutoScroll(CListCtrl & list, int nIndex);
 
+       void                            FreeManufacturers( Manufacturers & manufacturers );
+
        Manufacturers           m_manufacturers;
 
        CListCtrl                       m_manufacturerListCtrl;