Skip to content

Commit 2119fce

Browse files
[transaction.cpp] xaccTransSetDate has GDate on stack
avoid malloc/free
1 parent 2dfdb0b commit 2119fce

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

libgnucash/engine/Transaction.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,18 +1968,18 @@ xaccTransSetDateEnteredSecs (Transaction *trans, time64 secs)
19681968
void
19691969
xaccTransSetDate (Transaction *trans, int day, int mon, int year)
19701970
{
1971-
GDate *date;
19721971
if (!trans) return;
1973-
date = g_date_new_dmy(day, static_cast<GDateMonth>(mon), year);
1974-
if (!g_date_valid(date))
1972+
GDate date;
1973+
g_date_clear (&date, 1);
1974+
if (g_date_valid_dmy (day, static_cast<GDateMonth>(mon), year))
1975+
g_date_set_dmy (&date, day, static_cast<GDateMonth>(mon), year);
1976+
else
19751977
{
19761978
PWARN("Attempted to set invalid date %d-%d-%d; set today's date instead.",
19771979
year, mon, day);
1978-
g_free(date);
1979-
date = gnc_g_date_new_today();
1980+
gnc_gdate_set_today (&date);
19801981
}
1981-
xaccTransSetDatePostedGDate(trans, *date);
1982-
g_free(date);
1982+
xaccTransSetDatePostedGDate(trans, date);
19831983
}
19841984

19851985
void

0 commit comments

Comments
 (0)