diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-04 15:20:34 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-04 15:20:34 +0000 |
commit | 6b1e18a560171f38573600d1706bf7959d381150 (patch) | |
tree | 61c8160d063884dfc3ac8110a593671885a42608 | |
parent | e9051d2443755028d9f9ac4c9a6accbe6b150a21 (diff) | |
download | chromium_src-6b1e18a560171f38573600d1706bf7959d381150.zip chromium_src-6b1e18a560171f38573600d1706bf7959d381150.tar.gz chromium_src-6b1e18a560171f38573600d1706bf7959d381150.tar.bz2 |
Fixing potential memory leak in BookmarkCodec::DecodeNode.
Coverity finds a condition where this leaks. We are at the moment not using it in such a way that it leaks, but that might of course change. It looks to me like the API is not intended to be used in such a way anyway, so we can just check for it and return false.
BUG=15350
TEST=Decoding bookmarks should work as before.
Review URL: http://codereview.chromium.org/159075
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22379 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/bookmarks/bookmark_codec.cc | 11 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_codec.h | 5 |
2 files changed, 12 insertions, 4 deletions
diff --git a/chrome/browser/bookmarks/bookmark_codec.cc b/chrome/browser/bookmarks/bookmark_codec.cc index d666fe6..cae5f22 100644 --- a/chrome/browser/bookmarks/bookmark_codec.cc +++ b/chrome/browser/bookmarks/bookmark_codec.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -180,6 +180,13 @@ bool BookmarkCodec::DecodeChildren(const ListValue& child_value_list, bool BookmarkCodec::DecodeNode(const DictionaryValue& value, BookmarkNode* parent, BookmarkNode* node) { + // If no |node| is specified, we'll create one and add it to the |parent|. + // Therefore, in that case, |parent| must be non-NULL. + if (!node && !parent) { + NOTREACHED(); + return false; + } + std::string id_string; int64 id = 0; if (!value.GetString(kIdKey, &id_string) || !StringToInt64(id_string, &id)) @@ -209,7 +216,7 @@ bool BookmarkCodec::DecodeNode(const DictionaryValue& value, if (!node) node = new BookmarkNode(id, GURL(WideToUTF8(url_string))); else - return false; // Node invalid. + return false; // Node invalid. if (parent) parent->Add(parent->GetChildCount(), node); diff --git a/chrome/browser/bookmarks/bookmark_codec.h b/chrome/browser/bookmarks/bookmark_codec.h index becdf4e..25e9cb0 100644 --- a/chrome/browser/bookmarks/bookmark_codec.h +++ b/chrome/browser/bookmarks/bookmark_codec.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -109,7 +109,8 @@ class BookmarkCodec { // Decodes the supplied node from the supplied value. Child nodes are // created appropriately by way of DecodeChildren. If node is NULL a new - // node is created and added to parent, otherwise node is used. + // node is created and added to parent (parent must then be non-NULL), + // otherwise node is used. bool DecodeNode(const DictionaryValue& value, BookmarkNode* parent, BookmarkNode* node); |