From 54e0a2db9a8c63c76062b196958fd71f96677d9b Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 9 Nov 2010 21:06:39 +0000 Subject: [PATCH] - Fix a reference leak in CefXmlReaderImpl due to xml_close_callback not always being called. - Make include guards consistent in browser_web_worker.h git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@134 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser_web_worker.h | 6 +++--- libcef/xml_reader_impl.cc | 26 ++++---------------------- libcef/xml_reader_impl.h | 1 + 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/libcef/browser_web_worker.h b/libcef/browser_web_worker.h index 95795ad7d..8c504df4c 100644 --- a/libcef/browser_web_worker.h +++ b/libcef/browser_web_worker.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef BROWSER_WEB_WORKER_H_ -#define BROWSER_WEB_WORKER_H_ +#ifndef _BROWSER_WEB_WORKER_H +#define _BROWSER_WEB_WORKER_H #include "base/basictypes.h" #include "base/ref_counted.h" @@ -98,4 +98,4 @@ class BrowserWebWorker : public WebKit::WebWorker, DISALLOW_COPY_AND_ASSIGN(BrowserWebWorker); }; -#endif // BROWSER_WEB_WORKER_H_ +#endif // _BROWSER_WEB_WORKER_H diff --git a/libcef/xml_reader_impl.cc b/libcef/xml_reader_impl.cc index a421e24dc..5d3374a84 100644 --- a/libcef/xml_reader_impl.cc +++ b/libcef/xml_reader_impl.cc @@ -40,23 +40,6 @@ int XMLCALL xml_read_callback(void * context, char * buffer, int len) return reader->Read(buffer, 1, len); } -/** - * xmlInputCloseCallback: - * @context: an Input context - * - * Callback used in the I/O Input API to close the resource - * - * Returns 0 or -1 in case of error - */ -int XMLCALL xml_close_callback(void * context) -{ - CefRefPtr reader(static_cast(context)); - - // Release the reference added by CefXmlReaderImpl::Initialize(). - reader->Release(); - return 1; -} - /** * xmlTextReaderErrorFunc: * @arg: the user argument @@ -177,12 +160,8 @@ bool CefXmlReaderImpl::Initialize(CefRefPtr stream, if (!input_buffer) return false; - // Add a reference that will be released by xml_close_callback(). - stream->AddRef(); - input_buffer->context = stream.get(); - input_buffer->readcallback = xml_read_callback; - input_buffer->closecallback = xml_close_callback; + input_buffer->readcallback = xml_read_callback; // Create the text reader. reader_ = xmlNewTextReader(input_buffer, WideToUTF8(URI).c_str()); @@ -192,6 +171,9 @@ bool CefXmlReaderImpl::Initialize(CefRefPtr stream, return false; } + // Keep a reference to the stream. + stream_ = stream; + // Register the error callbacks. xmlTextReaderSetErrorHandler(reader_, xml_error_callback, this); xmlTextReaderSetStructuredErrorHandler(reader_, diff --git a/libcef/xml_reader_impl.h b/libcef/xml_reader_impl.h index 1205d1699..1c12898f5 100644 --- a/libcef/xml_reader_impl.h +++ b/libcef/xml_reader_impl.h @@ -62,6 +62,7 @@ public: protected: PlatformThreadId supported_thread_id_; + CefRefPtr stream_; xmlTextReaderPtr reader_; std::wstringstream error_buf_; };