summaryrefslogtreecommitdiffstats
path: root/webkit/glue/cpp_variant.cc
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-18 00:05:10 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-18 00:05:10 +0000
commitd517b7081d417c0ec79df0e236cb6bd9b58c22a3 (patch)
tree81522f4306ae72b8bd9758f1c4017ec28e766aa4 /webkit/glue/cpp_variant.cc
parent1056423d80de818876eee332cde2bde9618b1139 (diff)
downloadchromium_src-d517b7081d417c0ec79df0e236cb6bd9b58c22a3.zip
chromium_src-d517b7081d417c0ec79df0e236cb6bd9b58c22a3.tar.gz
chromium_src-d517b7081d417c0ec79df0e236cb6bd9b58c22a3.tar.bz2
Fix a memory leak found by Valgrind.
See https://developer.mozilla.org/en/NPN_GetProperty for doc on proper use of NPN_GetProperty. BUG=9515 Review URL: http://codereview.chromium.org/155730 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/cpp_variant.cc')
-rw-r--r--webkit/glue/cpp_variant.cc17
1 files changed, 11 insertions, 6 deletions
diff --git a/webkit/glue/cpp_variant.cc b/webkit/glue/cpp_variant.cc
index c0827c6..2f6be0c 100644
--- a/webkit/glue/cpp_variant.cc
+++ b/webkit/glue/cpp_variant.cc
@@ -229,19 +229,24 @@ std::vector<std::wstring> CppVariant::ToStringVector() const {
length = static_cast<int>(NPVARIANT_TO_DOUBLE(length_value));
else if (NPVARIANT_IS_INT32(length_value))
length = NPVARIANT_TO_INT32(length_value);
+ NPN_ReleaseVariantValue(&length_value);
+
// For sanity, only allow 100 items.
- length = std::min(100, length);
+ length = std::min(100, length);
for (int i = 0; i < length; ++i) {
// Get each of the items.
std::string index = StringPrintf("%d", i);
NPIdentifier index_id = NPN_GetStringIdentifier(index.c_str());
if (NPN_HasProperty(NULL, np_value, index_id)) {
NPVariant index_value;
- if (NPN_GetProperty(NULL, np_value, index_id, &index_value) &&
- NPVARIANT_IS_STRING(index_value)) {
- std::string string(NPVARIANT_TO_STRING(index_value).UTF8Characters,
- NPVARIANT_TO_STRING(index_value).UTF8Length);
- wstring_vector.push_back(UTF8ToWide(string));
+ if (NPN_GetProperty(NULL, np_value, index_id, &index_value)) {
+ if (NPVARIANT_IS_STRING(index_value)) {
+ std::string string(
+ NPVARIANT_TO_STRING(index_value).UTF8Characters,
+ NPVARIANT_TO_STRING(index_value).UTF8Length);
+ wstring_vector.push_back(UTF8ToWide(string));
+ }
+ NPN_ReleaseVariantValue(&index_value);
}
}
}