From ef3cd23c355aad534ffa99d2c8871776c0f548d4 Mon Sep 17 00:00:00 2001 From: "evan@chromium.org" Date: Thu, 18 Jun 2009 00:23:23 +0000 Subject: linux: NULL-initialize an array. A guess at fixing a crash seen by users. BUG=14483 Review URL: http://codereview.chromium.org/132001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18673 0039d316-1c4b-4281-b951-d872f2087c98 --- base/mime_util_linux.cc | 66 +++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 32 deletions(-) (limited to 'base') diff --git a/base/mime_util_linux.cc b/base/mime_util_linux.cc index a248bc0..39eab03 100644 --- a/base/mime_util_linux.cc +++ b/base/mime_util_linux.cc @@ -34,31 +34,35 @@ class MimeUtilConstants { const int kUpdateInterval; // Store icon directories and their mtimes. - std::map* icon_dirs; + std::map* icon_dirs_; // Store icon formats. - std::vector* icon_formats; + std::vector* icon_formats_; // Store loaded icon_theme. - std::map* icon_themes; + std::map* icon_themes_; static const size_t kDefaultThemeNum = 4; // The default theme. - IconTheme* default_themes[kDefaultThemeNum]; + IconTheme* default_themes_[kDefaultThemeNum]; - time_t last_check_time; + time_t last_check_time_; private: MimeUtilConstants() : kUpdateInterval(5), - icon_dirs(NULL), - icon_formats(NULL), - icon_themes(NULL), - last_check_time(0) { + icon_dirs_(NULL), + icon_formats_(NULL), + icon_themes_(NULL), + last_check_time_(0) { + for (size_t i = 0; i < kDefaultThemeNum; ++i) + default_themes_[i] = NULL; } ~MimeUtilConstants(); + friend struct DefaultSingletonTraits; + DISALLOW_COPY_AND_ASSIGN(MimeUtilConstants); }; @@ -146,7 +150,7 @@ IconTheme::IconTheme(const std::string& name) std::map::iterator iter; FilePath theme_path; std::map* icon_dirs = - Singleton::get()->icon_dirs; + Singleton::get()->icon_dirs_; for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) { theme_path = iter->first.Append(name); if (!file_util::DirectoryExists(theme_path)) @@ -206,7 +210,7 @@ FilePath IconTheme::GetIconPath(const std::string& icon_name, int size, IconTheme* IconTheme::LoadTheme(const std::string& theme_name) { scoped_ptr theme; std::map* icon_themes = - Singleton::get()->icon_themes; + Singleton::get()->icon_themes_; if (icon_themes->find(theme_name) != icon_themes->end()) { theme.reset((*icon_themes)[theme_name]); } else { @@ -223,7 +227,7 @@ FilePath IconTheme::GetIconPathUnderSubdir(const std::string& icon_name, FilePath icon_path; std::list::iterator dir_iter; std::vector* icon_formats = - Singleton::get()->icon_formats; + Singleton::get()->icon_formats_; for (dir_iter = dirs_.begin(); dir_iter != dirs_.end(); ++dir_iter) { for (size_t i = 0; i < icon_formats->size(); ++i) { icon_path = dir_iter->Append(subdir); @@ -371,7 +375,7 @@ bool IconTheme::SetDirectories(const std::string& dirs) { void TryAddIconDir(const FilePath& dir) { if (!file_util::DirectoryExists(dir)) return; - (*Singleton::get()->icon_dirs)[dir] = 0; + (*Singleton::get()->icon_dirs_)[dir] = 0; } // For a xdg directory |dir|, add the appropriate icon sub-directories. @@ -385,7 +389,7 @@ void AddXDGDataDir(const FilePath& dir) { // Enable or disable SVG support. void EnableSvgIcon(bool enable) { std::vector* icon_formats = - Singleton::get()->icon_formats; + Singleton::get()->icon_formats_; icon_formats->clear(); icon_formats->push_back(".png"); if (enable) { @@ -397,7 +401,7 @@ void EnableSvgIcon(bool enable) { // Add all the xdg icon directories. void InitIconDir() { - Singleton::get()->icon_dirs->clear(); + Singleton::get()->icon_dirs_->clear(); const char* home = getenv("HOME"); if (home) { FilePath legacy_data_dir(home); @@ -438,17 +442,17 @@ void EnsureUpdated() { time_t now = t.tv_sec; MimeUtilConstants* constants = Singleton::get(); - if (constants->last_check_time == 0) { - constants->icon_dirs = new std::map; - constants->icon_themes = new std::map; - constants->icon_formats = new std::vector; + if (constants->last_check_time_ == 0) { + constants->icon_dirs_ = new std::map; + constants->icon_themes_ = new std::map; + constants->icon_formats_ = new std::vector; EnableSvgIcon(kEnableSVG); InitIconDir(); - constants->last_check_time = now; + constants->last_check_time_ = now; } else { // TODO(thestig): something changed. start over. Upstream fix to Google // Gadgets for Linux. - if (now > constants->last_check_time + constants->kUpdateInterval) { + if (now > constants->last_check_time_ + constants->kUpdateInterval) { } } } @@ -458,8 +462,8 @@ FilePath LookupFallbackIcon(const std::string& icon_name) { FilePath icon; MimeUtilConstants* constants = Singleton::get(); std::map::iterator iter; - std::map* icon_dirs = constants->icon_dirs; - std::vector* icon_formats = constants->icon_formats; + std::map* icon_dirs = constants->icon_dirs_; + std::vector* icon_formats = constants->icon_formats_; for (iter = icon_dirs->begin(); iter != icon_dirs->end(); ++iter) { for (size_t i = 0; i < icon_formats->size(); ++i) { icon = iter->first.Append(icon_name + (*icon_formats)[i]); @@ -473,9 +477,7 @@ FilePath LookupFallbackIcon(const std::string& icon_name) { // Initialize the list of default themes. void InitDefaultThemes() { IconTheme** default_themes = - Singleton::get()->default_themes; - for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; ++i) - default_themes[i] = NULL; + Singleton::get()->default_themes_; char* env = getenv("KDE_FULL_SESSION"); if (env) { @@ -527,12 +529,12 @@ void InitDefaultThemes() { FilePath LookupIconInDefaultTheme(const std::string& icon_name, int size) { EnsureUpdated(); MimeUtilConstants* constants = Singleton::get(); - std::map* icon_themes = constants->icon_themes; + std::map* icon_themes = constants->icon_themes_; if (icon_themes->size() == 0) InitDefaultThemes(); FilePath icon_path; - IconTheme** default_themes = constants->default_themes; + IconTheme** default_themes = constants->default_themes_; for (size_t i = 0; i < MimeUtilConstants::kDefaultThemeNum; i++) { if (default_themes[i]) { icon_path = default_themes[i]->GetIconPath(icon_name, size, true); @@ -544,11 +546,11 @@ FilePath LookupIconInDefaultTheme(const std::string& icon_name, int size) { } MimeUtilConstants::~MimeUtilConstants() { - delete icon_dirs; - delete icon_formats; - delete icon_themes; + delete icon_dirs_; + delete icon_formats_; + delete icon_themes_; for (size_t i = 0; i < kDefaultThemeNum; i++) - delete default_themes[i]; + delete default_themes_[i]; } } // namespace -- cgit v1.1