Changeset 82805 in webkit


Ignore:
Timestamp:
Apr 4, 2011 1:50:50 AM (13 years ago)
Author:
Carlos Garcia Campos
Message:

2011-04-04 Carlos Garcia Campos <cgarcia@igalia.com>

Reviewed by Martin Robinson.

[GTK] Main loop sources are leaked in RunLoopGtk
https://bugs.webkit.org/show_bug.cgi?id=57618

  • Platform/RunLoop.h: (RunLoop::TimerBase::isRepeating):
  • Platform/gtk/RunLoopGtk.cpp: (RunLoop::~RunLoop): Make sure main loop is currently running before calling g_main_loop_quit(), RunLoop::stop() might have been called. (RunLoop::wakeUp): Use an idle source with default priority instead of a timeout one with a 0 interval. (RunLoop::TimerBase::clearTimerSource): New method to clear the timer. (RunLoop::TimerBase::destroyNotifyCallback): Destroy notify callback called when the source is destroyed to clear the timer. (RunLoop::TimerBase::timerFiredCallback): Use the same callback for repeating and no repeating timers. (RunLoop::TimerBase::start): g_source_attach() increments the source reference counter, so use GRefPtr to make sure the source is freed. (RunLoop::TimerBase::stop): Use clearTimerSource().
Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r82797 r82805  
     12011-04-04  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Main loop sources are leaked in RunLoopGtk
     6        https://bugs.webkit.org/show_bug.cgi?id=57618
     7
     8        * Platform/RunLoop.h:
     9        (RunLoop::TimerBase::isRepeating):
     10        * Platform/gtk/RunLoopGtk.cpp:
     11        (RunLoop::~RunLoop): Make sure main loop is currently running
     12        before calling g_main_loop_quit(), RunLoop::stop() might have been
     13        called.
     14        (RunLoop::wakeUp): Use an idle source with default priority
     15        instead of a timeout one with a 0 interval.
     16        (RunLoop::TimerBase::clearTimerSource): New method to clear the
     17        timer.
     18        (RunLoop::TimerBase::destroyNotifyCallback): Destroy notify
     19        callback called when the source is destroyed to clear the timer.
     20        (RunLoop::TimerBase::timerFiredCallback): Use the same callback for
     21        repeating and no repeating timers.
     22        (RunLoop::TimerBase::start): g_source_attach() increments the
     23        source reference counter, so use GRefPtr to make sure the source
     24        is freed.
     25        (RunLoop::TimerBase::stop): Use clearTimerSource().
     26
    1272011-04-03  Dan Bernstein  <mitz@apple.com>
    228
  • trunk/Source/WebKit2/Platform/RunLoop.h

    r73142 r82805  
    3535#include <wtf/Vector.h>
    3636#if PLATFORM(GTK)
     37#include <wtf/gobject/GRefPtr.h>
    3738typedef struct _GSource GSource;
    3839typedef struct _GMainLoop GMainLoop;
     
    8788        bool m_isRepeating;
    8889#elif PLATFORM(GTK)
    89         static gboolean oneShotTimerFired(RunLoop::TimerBase*);
    90         static gboolean repeatingTimerFired(RunLoop::TimerBase*);
    91         void resetTimerSource();
    92         GSource* m_timerSource;
     90        static gboolean timerFiredCallback(RunLoop::TimerBase*);
     91        static void destroyNotifyCallback(RunLoop::TimerBase*);
     92        gboolean isRepeating() const { return m_isRepeating; }
     93        void clearTimerSource();
     94        GRefPtr<GSource> m_timerSource;
     95        gboolean m_isRepeating;
    9396#endif
    9497    };
  • trunk/Source/WebKit2/Platform/gtk/RunLoopGtk.cpp

    r76916 r82805  
    4242{
    4343    if (m_runLoopMain) {
    44         g_main_loop_quit(m_runLoopMain);
     44        if (g_main_loop_is_running(m_runLoopMain))
     45            g_main_loop_quit(m_runLoopMain);
    4546        g_main_loop_unref(m_runLoopMain);
    4647    }
     
    7374void RunLoop::wakeUp()
    7475{
    75     GSource* source = g_timeout_source_new(0);
    76     g_source_set_callback(source, reinterpret_cast<GSourceFunc>(&RunLoop::queueWork), this, 0);
    77     g_source_attach(source, m_runLoopContext);
     76    GRefPtr<GSource> source = adoptGRef(g_idle_source_new());
     77    g_source_set_priority(source.get(), G_PRIORITY_DEFAULT);
     78    g_source_set_callback(source.get(), reinterpret_cast<GSourceFunc>(&RunLoop::queueWork), this, 0);
     79    g_source_attach(source.get(), m_runLoopContext);
    7880
    7981    g_main_context_wakeup(m_runLoopContext);
     
    9193}
    9294
    93 void RunLoop::TimerBase::resetTimerSource()
     95void RunLoop::TimerBase::clearTimerSource()
    9496{
    9597    m_timerSource = 0;
    9698}
    9799
    98 gboolean RunLoop::TimerBase::oneShotTimerFired(RunLoop::TimerBase* timer)
     100void RunLoop::TimerBase::destroyNotifyCallback(RunLoop::TimerBase* timer)
     101{
     102    timer->clearTimerSource();
     103}
     104
     105gboolean RunLoop::TimerBase::timerFiredCallback(RunLoop::TimerBase* timer)
    99106{
    100107    timer->fired();
    101     timer->resetTimerSource();
    102     return FALSE;
    103 }
    104 
    105 gboolean RunLoop::TimerBase::repeatingTimerFired(RunLoop::TimerBase* timer)
    106 {
    107     timer->fired();
    108     return TRUE;
     108    return timer->isRepeating();
    109109}
    110110
     
    114114        stop();
    115115
    116     m_timerSource = g_timeout_source_new(static_cast<guint>(fireInterval));
    117     if (repeat)
    118         g_source_set_callback(m_timerSource, reinterpret_cast<GSourceFunc>(&RunLoop::TimerBase::repeatingTimerFired), this, 0);
    119     else
    120         g_source_set_callback(m_timerSource, reinterpret_cast<GSourceFunc>(&RunLoop::TimerBase::oneShotTimerFired), this, 0);
    121     g_source_attach(m_timerSource, m_runLoop->m_runLoopContext);
     116    m_timerSource = adoptGRef(g_timeout_source_new(static_cast<guint>(fireInterval * 1000)));
     117    m_isRepeating = repeat;
     118    g_source_set_callback(m_timerSource.get(), reinterpret_cast<GSourceFunc>(&RunLoop::TimerBase::timerFiredCallback), this,
     119                          reinterpret_cast<GDestroyNotify>(&RunLoop::TimerBase::destroyNotifyCallback));
     120    g_source_attach(m_timerSource.get(), m_runLoop->m_runLoopContext);
    122121}
    123122
     
    127126        return;
    128127
    129     g_source_destroy(m_timerSource);
    130     m_timerSource = 0;
     128    g_source_destroy(m_timerSource.get());
     129    clearTimerSource();
    131130}
    132131
Note: See TracChangeset for help on using the changeset viewer.