Changeset 54835 in webkit


Ignore:
Timestamp:
Feb 16, 2010 2:53:46 PM (14 years ago)
Author:
mrowe@apple.com
Message:

Bug 34974: Leak of ScheduledAction during layout tests
<https://bugs.webkit.org/show_bug.cgi?id=34974>

Reviewed by Alexey Proskuryakov.

ScheduledAction::create was returning a raw pointer which was threaded down through to an OwnPtr in DOMTimer.
If any of the code paths in between hit an error case and returned early the raw pointer would be leaked. We
can avoid this by passing it as a PassOwnPtr. This will ensure that the ScheduledAction is cleaned up should
an error case be hit.

  • bindings/js/JSDOMWindowCustom.cpp:

(WebCore::JSDOMWindow::setTimeout): Store the newly-created ScheduledAction in an OwnPtr and then hand it off
as the function argument.
(WebCore::JSDOMWindow::setInterval): Ditto.

  • bindings/js/JSWorkerContextCustom.cpp:

(WebCore::JSWorkerContext::setTimeout): Ditto.
(WebCore::JSWorkerContext::setInterval): Ditto.

  • bindings/js/ScheduledAction.cpp:

(WebCore::ScheduledAction::create): Return a PassOwnPtr.

  • bindings/js/ScheduledAction.h:
  • page/DOMTimer.cpp:

(WebCore::DOMTimer::DOMTimer): Update argument type.
(WebCore::DOMTimer::install): Ditto.

  • page/DOMTimer.h:
  • page/DOMWindow.cpp:

(WebCore::DOMWindow::setTimeout): Ditto.
(WebCore::DOMWindow::setInterval): Ditto.

  • page/DOMWindow.h:
Location:
trunk/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r54834 r54835  
     12010-02-16  Mark Rowe  <mrowe@apple.com>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        Bug 34974: Leak of ScheduledAction during layout tests
     6        <https://bugs.webkit.org/show_bug.cgi?id=34974>
     7
     8        ScheduledAction::create was returning a raw pointer which was threaded down through to an OwnPtr in DOMTimer.
     9        If any of the code paths in between hit an error case and returned early the raw pointer would be leaked.  We
     10        can avoid this by passing it as a PassOwnPtr.  This will ensure that the ScheduledAction is cleaned up should
     11        an error case be hit.
     12
     13        * bindings/js/JSDOMWindowCustom.cpp:
     14        (WebCore::JSDOMWindow::setTimeout): Store the newly-created ScheduledAction in an OwnPtr and then hand it off
     15        as the function argument.
     16        (WebCore::JSDOMWindow::setInterval): Ditto.
     17        * bindings/js/JSWorkerContextCustom.cpp:
     18        (WebCore::JSWorkerContext::setTimeout): Ditto.
     19        (WebCore::JSWorkerContext::setInterval): Ditto.
     20        * bindings/js/ScheduledAction.cpp:
     21        (WebCore::ScheduledAction::create): Return a PassOwnPtr.
     22        * bindings/js/ScheduledAction.h:
     23        * page/DOMTimer.cpp:
     24        (WebCore::DOMTimer::DOMTimer): Update argument type.
     25        (WebCore::DOMTimer::install): Ditto.
     26        * page/DOMTimer.h:
     27        * page/DOMWindow.cpp:
     28        (WebCore::DOMWindow::setTimeout): Ditto.
     29        (WebCore::DOMWindow::setInterval): Ditto.
     30        * page/DOMWindow.h:
     31
    1322010-02-16  Nikolas Zimmermann  <nzimmermann@rim.com>
    233
  • trunk/WebCore/bindings/js/JSDOMWindowCustom.cpp

    r54789 r54835  
    913913JSValue JSDOMWindow::setTimeout(ExecState* exec, const ArgList& args)
    914914{
    915     ScheduledAction* action = ScheduledAction::create(exec, args, currentWorld(exec));
     915    OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, args, currentWorld(exec));
    916916    if (exec->hadException())
    917917        return jsUndefined();
     
    919919
    920920    ExceptionCode ec = 0;
    921     int result = impl()->setTimeout(action, delay, ec);
     921    int result = impl()->setTimeout(action.release(), delay, ec);
    922922    setDOMException(exec, ec);
    923923
     
    927927JSValue JSDOMWindow::setInterval(ExecState* exec, const ArgList& args)
    928928{
    929     ScheduledAction* action = ScheduledAction::create(exec, args, currentWorld(exec));
     929    OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, args, currentWorld(exec));
    930930    if (exec->hadException())
    931931        return jsUndefined();
     
    933933
    934934    ExceptionCode ec = 0;
    935     int result = impl()->setInterval(action, delay, ec);
     935    int result = impl()->setInterval(action.release(), delay, ec);
    936936    setDOMException(exec, ec);
    937937
  • trunk/WebCore/bindings/js/JSWorkerContextCustom.cpp

    r54400 r54835  
    144144JSValue JSWorkerContext::setTimeout(ExecState* exec, const ArgList& args)
    145145{
    146     ScheduledAction* action = ScheduledAction::create(exec, args, currentWorld(exec));
     146    OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, args, currentWorld(exec));
    147147    if (exec->hadException())
    148148        return jsUndefined();
    149149    int delay = args.at(1).toInt32(exec);
    150     return jsNumber(exec, impl()->setTimeout(action, delay));
     150    return jsNumber(exec, impl()->setTimeout(action.release(), delay));
    151151}
    152152
    153153JSValue JSWorkerContext::setInterval(ExecState* exec, const ArgList& args)
    154154{
    155     ScheduledAction* action = ScheduledAction::create(exec, args, currentWorld(exec));
     155    OwnPtr<ScheduledAction> action = ScheduledAction::create(exec, args, currentWorld(exec));
    156156    if (exec->hadException())
    157157        return jsUndefined();
    158158    int delay = args.at(1).toInt32(exec);
    159     return jsNumber(exec, impl()->setInterval(action, delay));
     159    return jsNumber(exec, impl()->setInterval(action.release(), delay));
    160160}
    161161
  • trunk/WebCore/bindings/js/ScheduledAction.cpp

    r53046 r54835  
    4848namespace WebCore {
    4949
    50 ScheduledAction* ScheduledAction::create(ExecState* exec, const ArgList& args, DOMWrapperWorld* isolatedWorld)
     50PassOwnPtr<ScheduledAction> ScheduledAction::create(ExecState* exec, const ArgList& args, DOMWrapperWorld* isolatedWorld)
    5151{
    5252    JSValue v = args.at(0);
  • trunk/WebCore/bindings/js/ScheduledAction.h

    r52281 r54835  
    2525#include <runtime/JSCell.h>
    2626#include <runtime/Protect.h>
     27#include <wtf/PassOwnPtr.h>
    2728#include <wtf/Vector.h>
    2829
     
    4344    class ScheduledAction : public Noncopyable {
    4445    public:
    45         static ScheduledAction* create(JSC::ExecState*, const JSC::ArgList&, DOMWrapperWorld* isolatedWorld);
     46        static PassOwnPtr<ScheduledAction> create(JSC::ExecState*, const JSC::ArgList&, DOMWrapperWorld* isolatedWorld);
    4647
    4748        void execute(ScriptExecutionContext*);
     
    5758        void executeFunctionInContext(JSC::JSGlobalObject*, JSC::JSValue thisValue);
    5859        void execute(Document*);
    59 #if ENABLE(WORKERS)       
     60#if ENABLE(WORKERS)
    6061        void execute(WorkerContext*);
    6162#endif
  • trunk/WebCore/page/DOMTimer.cpp

    r50489 r54835  
    4444static int timerNestingLevel = 0;
    4545
    46 DOMTimer::DOMTimer(ScriptExecutionContext* context, ScheduledAction* action, int timeout, bool singleShot)
     46DOMTimer::DOMTimer(ScriptExecutionContext* context, PassOwnPtr<ScheduledAction> action, int timeout, bool singleShot)
    4747    : ActiveDOMObject(context, this)
    4848    , m_action(action)
     
    8383}
    8484
    85 int DOMTimer::install(ScriptExecutionContext* context, ScheduledAction* action, int timeout, bool singleShot)
     85int DOMTimer::install(ScriptExecutionContext* context, PassOwnPtr<ScheduledAction> action, int timeout, bool singleShot)
    8686{
    8787    // DOMTimer constructor links the new timer into a list of ActiveDOMObjects held by the 'context'.
  • trunk/WebCore/page/DOMTimer.h

    r50068 r54835  
    2929
    3030#include "ActiveDOMObject.h"
     31#include "ScheduledAction.h"
    3132#include "Timer.h"
    3233#include <wtf/OwnPtr.h>
     34#include <wtf/PassOwnPtr.h>
    3335
    3436namespace WebCore {
    3537
    3638    class InspectorTimelineAgent;
    37     class ScheduledAction;
    3839
    3940    class DOMTimer : public TimerBase, public ActiveDOMObject {
     
    4243        // Creates a new timer owned by specified ScriptExecutionContext, starts it
    4344        // and returns its Id.
    44         static int install(ScriptExecutionContext*, ScheduledAction*, int timeout, bool singleShot);
     45        static int install(ScriptExecutionContext*, PassOwnPtr<ScheduledAction>, int timeout, bool singleShot);
    4546        static void removeById(ScriptExecutionContext*, int timeoutId);
    4647
     
    6061
    6162    private:
    62         DOMTimer(ScriptExecutionContext*, ScheduledAction*, int timeout, bool singleShot);
     63        DOMTimer(ScriptExecutionContext*, PassOwnPtr<ScheduledAction>, int timeout, bool singleShot);
    6364        virtual void fired();
    6465
  • trunk/WebCore/page/DOMWindow.cpp

    r54182 r54835  
    12531253}
    12541254
    1255 int DOMWindow::setTimeout(ScheduledAction* action, int timeout, ExceptionCode& ec)
     1255int DOMWindow::setTimeout(PassOwnPtr<ScheduledAction> action, int timeout, ExceptionCode& ec)
    12561256{
    12571257    ScriptExecutionContext* context = scriptExecutionContext();
     
    12711271}
    12721272
    1273 int DOMWindow::setInterval(ScheduledAction* action, int timeout, ExceptionCode& ec)
     1273int DOMWindow::setInterval(PassOwnPtr<ScheduledAction> action, int timeout, ExceptionCode& ec)
    12741274{
    12751275    ScriptExecutionContext* context = scriptExecutionContext();
  • trunk/WebCore/page/DOMWindow.h

    r54085 r54835  
    238238
    239239        // Timers
    240         int setTimeout(ScheduledAction*, int timeout, ExceptionCode&);
     240        int setTimeout(PassOwnPtr<ScheduledAction>, int timeout, ExceptionCode&);
    241241        void clearTimeout(int timeoutId);
    242         int setInterval(ScheduledAction*, int timeout, ExceptionCode&);
     242        int setInterval(PassOwnPtr<ScheduledAction>, int timeout, ExceptionCode&);
    243243        void clearInterval(int timeoutId);
    244244
Note: See TracChangeset for help on using the changeset viewer.