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

Side by Side Diff: base/json/json_value_converter.h

Issue 9113075: Fix a potential memory leak bug. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 11 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
« no previous file with comments | « no previous file | base/json/json_value_converter_unittest.cc » ('j') | 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 #ifndef BASE_JSON_JSON_VALUE_CONVERTER_H_ 5 #ifndef BASE_JSON_JSON_VALUE_CONVERTER_H_
6 #define BASE_JSON_JSON_VALUE_CONVERTER_H_ 6 #define BASE_JSON_JSON_VALUE_CONVERTER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // The field is not a list. 252 // The field is not a list.
253 return false; 253 return false;
254 } 254 }
255 255
256 field->reserve(list->GetSize()); 256 field->reserve(list->GetSize());
257 for (size_t i = 0; i < list->GetSize(); ++i) { 257 for (size_t i = 0; i < list->GetSize(); ++i) {
258 base::Value* element = NULL; 258 base::Value* element = NULL;
259 if (!list->Get(i, &element)) 259 if (!list->Get(i, &element))
260 continue; 260 continue;
261 261
262 Element *e = new Element; 262 scoped_ptr<Element> e(new Element);
263 if (basic_converter_.Convert(*element, e)) { 263 if (basic_converter_.Convert(*element, e.get())) {
264 field->push_back(e); 264 field->push_back(e.release());
265 } else { 265 } else {
266 DVLOG(1) << "failure at " << i << "-th element"; 266 DVLOG(1) << "failure at " << i << "-th element";
267 return false; 267 return false;
268 } 268 }
269 } 269 }
270 return true; 270 return true;
271 } 271 }
272 272
273 private: 273 private:
274 BasicValueConverter<Element> basic_converter_; 274 BasicValueConverter<Element> basic_converter_;
(...skipping 11 matching lines...) Expand all
286 const base::ListValue* list = NULL; 286 const base::ListValue* list = NULL;
287 if (!value.GetAsList(&list)) 287 if (!value.GetAsList(&list))
288 return false; 288 return false;
289 289
290 field->reserve(list->GetSize()); 290 field->reserve(list->GetSize());
291 for (size_t i = 0; i < list->GetSize(); ++i) { 291 for (size_t i = 0; i < list->GetSize(); ++i) {
292 base::Value* element = NULL; 292 base::Value* element = NULL;
293 if (!list->Get(i, &element)) 293 if (!list->Get(i, &element))
294 continue; 294 continue;
295 295
296 NestedType* nested = new NestedType(); 296 scoped_ptr<NestedType> nested(new NestedType);
297 if (converter_.Convert(*element, nested)) { 297 if (converter_.Convert(*element, nested.get())) {
298 field->push_back(nested); 298 field->push_back(nested.release());
299 } else { 299 } else {
300 DVLOG(1) << "failure at " << i << "-th element"; 300 DVLOG(1) << "failure at " << i << "-th element";
301 return false; 301 return false;
302 } 302 }
303 } 303 }
304 return true; 304 return true;
305 } 305 }
306 306
307 private: 307 private:
308 JSONValueConverter<NestedType> converter_; 308 JSONValueConverter<NestedType> converter_;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 437
438 private: 438 private:
439 ScopedVector<internal::FieldConverterBase> fields_; 439 ScopedVector<internal::FieldConverterBase> fields_;
440 440
441 DISALLOW_COPY_AND_ASSIGN(JSONValueConverter); 441 DISALLOW_COPY_AND_ASSIGN(JSONValueConverter);
442 }; 442 };
443 443
444 } // namespace base 444 } // namespace base
445 445
446 #endif // BASE_JSON_JSON_VALUE_CONVERTER_H_ 446 #endif // BASE_JSON_JSON_VALUE_CONVERTER_H_
OLDNEW
« no previous file with comments | « no previous file | base/json/json_value_converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698