From 277b908150e53f434ae722c5998e7e2570c69244 Mon Sep 17 00:00:00 2001 From: "ager@chromium.org" Date: Wed, 24 Nov 2010 09:21:29 +0000 Subject: [PATCH] Fix the process sample to actually dispose the contexts used for processors. Review URL: http://codereview.chromium.org/5302004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5882 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- samples/process.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/samples/process.cc b/samples/process.cc index 9233c0d..6be4ea5 100644 --- a/samples/process.cc +++ b/samples/process.cc @@ -152,18 +152,16 @@ bool JsHttpRequestProcessor::Initialize(map* opts, Handle global = ObjectTemplate::New(); global->Set(String::New("log"), FunctionTemplate::New(LogCallback)); - // Each processor gets its own context so different processors - // don't affect each other (ignore the first three lines). - Handle context = Context::New(NULL, global); - - // Store the context in the processor object in a persistent handle, - // since we want the reference to remain after we return from this - // method. - context_ = Persistent::New(context); + // Each processor gets its own context so different processors don't + // affect each other. Context::New returns a persistent handle which + // is what we need for the reference to remain after we return from + // this method. That persistent handle has to be disposed in the + // destructor. + context_ = Context::New(NULL, global); // Enter the new context so all the following operations take place // within it. - Context::Scope context_scope(context); + Context::Scope context_scope(context_); // Make the options mapping available within the context if (!InstallMaps(opts, output)) @@ -176,7 +174,7 @@ bool JsHttpRequestProcessor::Initialize(map* opts, // The script compiled and ran correctly. Now we fetch out the // Process function from the global object. Handle process_name = String::New("Process"); - Handle process_val = context->Global()->Get(process_name); + Handle process_val = context_->Global()->Get(process_name); // If there is no Process function, or if it is not a function, // bail out -- 2.7.4