Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: base/json/json_parser.cc

Issue 10386168: Fix a leak in JSONParser::Parse when using hidden root optimizations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_parser.h" 5 #include "base/json/json_parser.h"
6 6
7 #include "base/float_util.h" 7 #include "base/float_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (!CanConsume(1) || (NextChar() && GetNextToken() != T_END_OF_INPUT)) { 251 if (!CanConsume(1) || (NextChar() && GetNextToken() != T_END_OF_INPUT)) {
252 ReportError(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, 1); 252 ReportError(JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT, 1);
253 return NULL; 253 return NULL;
254 } 254 }
255 } 255 }
256 256
257 // Dictionaries and lists can contain JSONStringValues, so wrap them in a 257 // Dictionaries and lists can contain JSONStringValues, so wrap them in a
258 // hidden root. 258 // hidden root.
259 if (!(options_ & JSON_DETACHABLE_CHILDREN)) { 259 if (!(options_ & JSON_DETACHABLE_CHILDREN)) {
260 if (root->IsType(Value::TYPE_DICTIONARY)) { 260 if (root->IsType(Value::TYPE_DICTIONARY)) {
261 return new DictionaryHiddenRootValue(&input_copy, root.release()); 261 return new DictionaryHiddenRootValue(&input_copy, root.get());
262 } else if (root->IsType(Value::TYPE_LIST)) { 262 } else if (root->IsType(Value::TYPE_LIST)) {
263 return new ListHiddenRootValue(&input_copy, root.release()); 263 return new ListHiddenRootValue(&input_copy, root.get());
264 } else if (root->IsType(Value::TYPE_STRING)) { 264 } else if (root->IsType(Value::TYPE_STRING)) {
265 // A string type could be a JSONStringValue, but because there's no 265 // A string type could be a JSONStringValue, but because there's no
266 // corresponding HiddenRootValue, the memory will be lost. Deep copy to 266 // corresponding HiddenRootValue, the memory will be lost. Deep copy to
267 // preserve it. 267 // preserve it.
268 return root->DeepCopy(); 268 return root->DeepCopy();
269 } 269 }
270 } 270 }
271 271
272 // All other values can be returned directly. 272 // All other values can be returned directly.
273 return root.release(); 273 return root.release();
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 const std::string& description) { 964 const std::string& description) {
965 if (line || column) { 965 if (line || column) {
966 return StringPrintf("Line: %i, column: %i, %s", 966 return StringPrintf("Line: %i, column: %i, %s",
967 line, column, description.c_str()); 967 line, column, description.c_str());
968 } 968 }
969 return description; 969 return description;
970 } 970 }
971 971
972 } // namespace internal 972 } // namespace internal
973 } // namespace base 973 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698