From f73db6646111bfa9402c4615f9ee3f93da58373c Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 25 Apr 2012 20:01:47 +0000 Subject: [PATCH] Merge revision 603 changes: - Fix memory leak when returning zero-length strings from V8 (issue #581). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1025@605 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- include/internal/cef_string_wrappers.h | 2 +- libcef/v8_impl.cc | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/internal/cef_string_wrappers.h b/include/internal/cef_string_wrappers.h index e6b29ebb4..c0507c1cc 100644 --- a/include/internal/cef_string_wrappers.h +++ b/include/internal/cef_string_wrappers.h @@ -414,7 +414,7 @@ class CefStringBase { // Clear the string data. /// void clear() { - if (!empty()) + if (string_) traits::clear(string_); } diff --git a/libcef/v8_impl.cc b/libcef/v8_impl.cc index 3720d8889..e7dc8b3e6 100644 --- a/libcef/v8_impl.cc +++ b/libcef/v8_impl.cc @@ -140,6 +140,8 @@ void GetCefString(v8::Handle str, CefString& out) { #if defined(CEF_STRING_TYPE_WIDE) // Allocate enough space for a worst-case conversion. int len = str->Utf8Length(); + if (len == 0) + return; char* buf = new char[len + 1]; str->WriteUtf8(buf, len + 1); @@ -151,11 +153,15 @@ void GetCefString(v8::Handle str, CefString& out) { #else // !defined(CEF_STRING_TYPE_WIDE) #if defined(CEF_STRING_TYPE_UTF16) int len = str->Length(); + if (len == 0) + return; char16* buf = new char16[len + 1]; str->Write(reinterpret_cast(buf), 0, len + 1); #else // Allocate enough space for a worst-case conversion. int len = str->Utf8Length(); + if (len == 0) + return; char* buf = new char[len + 1]; str->WriteUtf8(buf, len + 1); #endif