Skip to content

Commit

Permalink
Fix a potential memory leak bug.
Browse files Browse the repository at this point in the history
BUG=
TEST=


Review URL: http://codereview.chromium.org/9113075

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119269 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
mukai@chromium.org committed Jan 26, 2012
1 parent 15b1224 commit 50fa6f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
12 changes: 6 additions & 6 deletions base/json/json_value_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ class RepeatedValueConverter : public ValueConverter<ScopedVector<Element> > {
if (!list->Get(i, &element))
continue;

Element *e = new Element;
if (basic_converter_.Convert(*element, e)) {
field->push_back(e);
scoped_ptr<Element> e(new Element);
if (basic_converter_.Convert(*element, e.get())) {
field->push_back(e.release());
} else {
DVLOG(1) << "failure at " << i << "-th element";
return false;
Expand Down Expand Up @@ -293,9 +293,9 @@ class RepeatedMessageConverter
if (!list->Get(i, &element))
continue;

NestedType* nested = new NestedType();
if (converter_.Convert(*element, nested)) {
field->push_back(nested);
scoped_ptr<NestedType> nested(new NestedType);
if (converter_.Convert(*element, nested.get())) {
field->push_back(nested.release());
} else {
DVLOG(1) << "failure at " << i << "-th element";
return false;
Expand Down
17 changes: 17 additions & 0 deletions base/json/json_value_converter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,21 @@ TEST(JSONValueConverterTest, EnumParserFails) {
// No check the values as mentioned above.
}

TEST(JSONValueConverterTest, RepeatedValueErrorInTheMiddle) {
const char normal_data[] =
"{\n"
" \"foo\": 1,\n"
" \"bar\": \"bar\",\n"
" \"baz\": true,\n"
" \"simple_enum\": \"baz\","
" \"ints\": [1, false]"
"}\n";

scoped_ptr<Value> value(base::JSONReader::Read(normal_data, false));
SimpleMessage message;
base::JSONValueConverter<SimpleMessage> converter;
EXPECT_FALSE(converter.Convert(*value.get(), &message));
// No check the values as mentioned above.
}

} // namespace base

0 comments on commit 50fa6f9

Please sign in to comment.