From 57abfd7ef8b4500b7a0c14d136d397ecf974163b Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 22 May 2010 13:08:53 -0400 Subject: Temporary accounts were referenced after deletion Fixes D53C98E5-506D-4CE5-91A3-7666FD33B65B --- src/account.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/account.cc') diff --git a/src/account.cc b/src/account.cc index e02d21d7..46f37091 100644 --- a/src/account.cc +++ b/src/account.cc @@ -43,8 +43,16 @@ account_t::~account_t() TRACE_DTOR(account_t); foreach (accounts_map::value_type& pair, accounts) - if (! pair.second->has_flags(ACCOUNT_TEMP)) + if (! pair.second->has_flags(ACCOUNT_TEMP) || + has_flags(ACCOUNT_TEMP)) checked_delete(pair.second); + + foreach (post_t * post, posts) { + if (post->account) { + assert(post->account == this); + post->account = NULL; + } + } } account_t * account_t::find_account(const string& name, @@ -79,6 +87,14 @@ account_t * account_t::find_account(const string& name, return NULL; account = new account_t(this, first); + + // An account created within a temporary or generated account is itself + // temporary or generated, so that the whole tree has the same status. + if (has_flags(ACCOUNT_TEMP)) + account->add_flags(ACCOUNT_TEMP); + if (has_flags(ACCOUNT_GENERATED)) + account->add_flags(ACCOUNT_GENERATED); + std::pair result = accounts.insert(accounts_map::value_type(first, account)); assert(result.second); -- cgit v1.2.3 From e0c5f6db30382960fa60739c368e3700e5f71b67 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 2 Jun 2010 00:19:07 -0400 Subject: Fixed two memory reference errors --- src/account.cc | 11 +++-------- src/times.cc | 13 ++++++------- 2 files changed, 9 insertions(+), 15 deletions(-) (limited to 'src/account.cc') diff --git a/src/account.cc b/src/account.cc index 46f37091..8d4341e7 100644 --- a/src/account.cc +++ b/src/account.cc @@ -42,16 +42,11 @@ account_t::~account_t() { TRACE_DTOR(account_t); - foreach (accounts_map::value_type& pair, accounts) + foreach (accounts_map::value_type& pair, accounts) { if (! pair.second->has_flags(ACCOUNT_TEMP) || - has_flags(ACCOUNT_TEMP)) + has_flags(ACCOUNT_TEMP)) { checked_delete(pair.second); - - foreach (post_t * post, posts) { - if (post->account) { - assert(post->account == this); - post->account = NULL; - } + } } } diff --git a/src/times.cc b/src/times.cc index 35082f51..a7906aee 100644 --- a/src/times.cc +++ b/src/times.cc @@ -197,8 +197,6 @@ namespace { optional_year year, date_traits_t * traits = NULL) { - date_t when; - VERIFY(std::strlen(date_str) < 127); char buf[128]; @@ -208,7 +206,7 @@ namespace { if (*p == '.' || *p == '-') *p = '/'; - when = io.parse(buf); + date_t when = io.parse(buf); if (! when.is_not_a_date()) { DEBUG("times.parse", "Passed date string: " << date_str); @@ -216,12 +214,13 @@ namespace { DEBUG("times.parse", "Parsed result is: " << when); DEBUG("times.parse", "Formatted result is: " << io.format(when)); - const char * p = io.format(when).c_str(); + string when_str = io.format(when); + + const char * p = when_str.c_str(); const char * q = buf; - for (; *p != '\0' && *q != '\0'; - p++, q++) { + for (; *p && *q; p++, q++) { if (*p != *q && *p == '0') p++; - if (*p != *q) break; + if (! *p || *p != *q) break; } if (*p != '\0' || *q != '\0') throw_(date_error, _("Invalid date: %1") << date_str); -- cgit v1.2.3