Changeset d26c3b950032d169b2d19dfccdf444256264c162

Show
Ignore:
Timestamp:
09/10/09 05:37:41 (4 years ago)
Author:
Armin Burgmeier <armin@…>
git-author:
Armin Burgmeier <armin@arbur.net> / 2009-09-09T23:30:56Z-0400
Parents:
81f1f55f4c81c36b08fffb6d8123e7b0be1fdcd5
Children:
b483a11d3443e16937dd7c8586c1a068e68e6bbd
git-committer:
Armin Burgmeier <armin@arbur.net> / 2009-09-09T23:37:41Z-0400
Message:

remote-url-open: Made the UNIQUE_GOBBY_CONNECT case exception-safe

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r81f1f55 rd26c3b9  
     12009-09-09  Armin Burgmeier  <armin@arbur.net> 
     2 
     3        * code/window.cpp (on_message_received): Don't leak the uris vector 
     4        when an exception is thrown. 
     5 
    162009-09-09  Benjamin Herr  <ben@0x539.de> 
    27 
  • code/window.cpp

    r81f1f55 rd26c3b9  
    241241try 
    242242{ 
     243        struct uris_holder 
     244        { 
     245                uris_holder(gchar** uris): uris(uris) {} 
     246                ~uris_holder() { if(uris) g_strfreev(uris); } 
     247                operator gchar* const*() const { return uris; } 
     248 
     249                gchar** uris; 
     250 
     251        private: 
     252                uris_holder(const uris_holder&); 
     253                uris_holder& operator=(const uris_holder&); 
     254        }; 
     255 
    243256        switch (command) 
    244257        { 
     
    250263        case UNIQUE_OPEN: 
    251264                { 
    252                         gchar** uris = unique_message_data_get_uris(message); 
    253                         if (!uris || !uris[0]) 
     265                        uris_holder uris( 
     266                                unique_message_data_get_uris(message)); 
     267                        if(!uris || !uris[0]) 
    254268                                return UNIQUE_RESPONSE_FAIL; 
    255269                        if(uris[1]) // multiple files? 
     
    257271                                TaskOpenMultiple* task = 
    258272                                        new TaskOpenMultiple(m_commands_file); 
    259                                 for (const gchar* const* p = uris; *p; ++p) 
     273                                for(const gchar* const* p = uris; *p; ++p) 
    260274                                        task->add_file(*p); 
    261275                                m_commands_file.set_task(task); 
     
    268282                                m_commands_file.set_task(task); 
    269283                        } 
    270                         g_strfreev(uris); 
    271284                        return UNIQUE_RESPONSE_OK; 
    272285                } 
    273286        case UNIQUE_GOBBY_CONNECT: 
    274287                { 
    275                         gchar** uris = unique_message_data_get_uris(message); 
     288                        uris_holder uris(unique_message_data_get_uris(message)); 
    276289                        if(!uris || !uris[0]) 
    277290                                return UNIQUE_RESPONSE_FAIL; 
    278                         // TODO: I do not have a very strong intuition that 
    279                         // this is not going to throw, ever. We should 
    280                         // probably handle that. 
    281291                        for(const gchar* const* p = uris; *p; ++p) 
    282292                        { 
    283                                 if(!g_str_has_prefix(*p, "infinote://")) 
    284                                 { 
    285                                         g_strfreev(uris); 
     293                                const gchar protocol[] = "infinote://"; 
     294                                if(!g_str_has_prefix(*p, protocol)) 
    286295                                        return UNIQUE_RESPONSE_FAIL; 
    287                                 } 
    288                                 connect_to_host(*p + sizeof("infinote://")-1); 
     296                                connect_to_host(*p + sizeof(protocol) - 1); 
    289297                        } 
    290                         g_strfreev(uris); 
    291298                        return UNIQUE_RESPONSE_OK; 
    292299                } 
     
    294301                return UNIQUE_RESPONSE_PASSTHROUGH; 
    295302        } 
    296 } catch (...) { 
     303} 
     304// For example, connect_to_host might throw Glib::ThreadError 
     305catch(const Glib::Exception& error) 
     306{ 
     307        // TODO: Do we want to show a dialog here? 
     308        g_warning("Failed to process IPC message: %s", error.what().c_str()); 
     309        return UNIQUE_RESPONSE_FAIL; 
     310} 
     311catch (...) 
     312{ 
    297313        g_assert_not_reached(); 
    298314        return UNIQUE_RESPONSE_FAIL;