diff --git a/src/register/basiccell.c b/src/register/basiccell.c index 6a8b2fc77b..7d0219b6c4 100644 --- a/src/register/basiccell.c +++ b/src/register/basiccell.c @@ -67,13 +67,13 @@ BasicCellHelpValue(BasicCell *cell) /* ===================================================== */ -void -xaccInitBasicCell (BasicCell *cell) +static void +xaccClearBasicCell (BasicCell *cell) { cell->changed = 0; cell->conditionally_changed = 0; - cell->value = g_strdup(""); + cell->value = NULL; cell->blank_help = NULL; cell->set_value = NULL; cell->enter_cell = NULL; @@ -83,13 +83,23 @@ xaccInitBasicCell (BasicCell *cell) cell->realize = NULL; cell->move = NULL; cell->destroy = NULL; - cell->get_help_value = BasicCellHelpValue; + cell->get_help_value = NULL; cell->is_popup = FALSE; cell->gui_private = NULL; } +void +xaccInitBasicCell (BasicCell *cell) +{ + xaccClearBasicCell (cell); + + cell->value = g_strdup (""); + + cell->get_help_value = BasicCellHelpValue; +} + /* ===================================================== */ void @@ -107,7 +117,7 @@ xaccDestroyBasicCell (BasicCell *cell) cell->blank_help = NULL; /* help prevent access to freed memory */ - xaccInitBasicCell (cell); + xaccClearBasicCell (cell); /* free the object itself */ g_free (cell); @@ -121,14 +131,16 @@ xaccSetBasicCellValue (BasicCell *cell, const char *val) CellSetValueFunc cb; cb = cell->set_value; - if (cb) { + if (cb) + { /* avoid recursion by disabling the * callback while it's being called. */ cell->set_value = NULL; cb (cell, val); cell->set_value = cb; } - else { + else + { g_free (cell->value); if (val) cell->value = g_strdup (val); @@ -145,13 +157,12 @@ xaccSetBasicCellBlankHelp (BasicCell *cell, const char *blank_help) if (cell == NULL) return; - if (cell->blank_help != NULL) - g_free(cell->blank_help); + g_free (cell->blank_help); if (blank_help == NULL) cell->blank_help = NULL; else - cell->blank_help = g_strdup(blank_help); + cell->blank_help = g_strdup (blank_help); } /* ===================================================== */ diff --git a/src/register/cellblock.c b/src/register/cellblock.c index 7e2548a26f..033ba5c630 100644 --- a/src/register/cellblock.c +++ b/src/register/cellblock.c @@ -80,6 +80,9 @@ gnc_cellblock_cell_destroy (gpointer _cb_cell, gpointer user_data) if (cb_cell == NULL) return; + cb_cell->cell = NULL; + cb_cell->cell_type = -1; + g_free(cb_cell->label); cb_cell->label = NULL; diff --git a/src/register/numcell.c b/src/register/numcell.c index 84c4bb0442..12ac02fc71 100644 --- a/src/register/numcell.c +++ b/src/register/numcell.c @@ -161,7 +161,7 @@ xaccMallocNumCell (void) { NumCell *cell; - cell = g_new(NumCell, 1); + cell = g_new0 (NumCell, 1); xaccInitNumCell (cell); diff --git a/src/register/pricecell.c b/src/register/pricecell.c index b6bbea44d8..34f0b5ae5a 100644 --- a/src/register/pricecell.c +++ b/src/register/pricecell.c @@ -199,7 +199,7 @@ xaccMallocPriceCell (void) { PriceCell *cell; - cell = g_new(PriceCell, 1); + cell = g_new0 (PriceCell, 1); xaccInitPriceCell (cell); diff --git a/src/register/quickfillcell.c b/src/register/quickfillcell.c index 2f68b108c8..c6f6a17deb 100644 --- a/src/register/quickfillcell.c +++ b/src/register/quickfillcell.c @@ -170,7 +170,7 @@ xaccMallocQuickFillCell (void) { QuickFillCell *cell; - cell = g_new(QuickFillCell, 1); + cell = g_new0 (QuickFillCell, 1); xaccInitQuickFillCell (cell); diff --git a/src/register/recncell.c b/src/register/recncell.c index 7dd0666133..f60aa5641d 100644 --- a/src/register/recncell.c +++ b/src/register/recncell.c @@ -54,6 +54,8 @@ static RecnCellStringGetter string_getter = NULL; /* This static indicates the debugging module that this .o belongs to. */ static short module = MOD_REGISTER; +static void RecnSetValue (BasicCell *_cell, const char *value); + /* ================================================ */ @@ -107,12 +109,23 @@ RecnEnter (BasicCell *_cell, /* ================================================ */ +static void +xaccInitRecnCell (RecnCell *cell) +{ + xaccInitBasicCell(&cell->cell); + + xaccRecnCellSetFlag(cell, NREC); + + cell->cell.enter_cell = RecnEnter; + cell->cell.set_value = RecnSetValue; +} + RecnCell * xaccMallocRecnCell (void) { RecnCell * cell; - cell = g_new(RecnCell, 1); + cell = g_new0 (RecnCell, 1); xaccInitRecnCell (cell); @@ -156,19 +169,6 @@ RecnSetValue (BasicCell *_cell, const char *value) /* ================================================ */ -void -xaccInitRecnCell (RecnCell *cell) -{ - xaccInitBasicCell(&cell->cell); - - xaccRecnCellSetFlag(cell, NREC); - - cell->cell.enter_cell = RecnEnter; - cell->cell.set_value = RecnSetValue; -} - -/* ================================================ */ - void xaccDestroyRecnCell (RecnCell *cell) { diff --git a/src/register/recncell.h b/src/register/recncell.h index 88bb56ecf5..80ac84934f 100644 --- a/src/register/recncell.h +++ b/src/register/recncell.h @@ -50,7 +50,6 @@ typedef struct _RecnCell } RecnCell; RecnCell * xaccMallocRecnCell (void); -void xaccInitRecnCell (RecnCell *cell); void xaccDestroyRecnCell (RecnCell *cell); void xaccRecnCellSetFlag (RecnCell *cell, char reconciled_flag); diff --git a/src/register/splitreg.c b/src/register/splitreg.c index fd1155ed0b..90ce9edaa8 100644 --- a/src/register/splitreg.c +++ b/src/register/splitreg.c @@ -978,6 +978,7 @@ xaccDestroySplitRegister (SplitRegister *reg) reg->cursor_journal_double = NULL; reg->cursor_split = NULL; + xaccDestroyBasicCell (reg->nullCell); xaccDestroyDateCell (reg->dateCell); xaccDestroyNumCell (reg->numCell); xaccDestroyQuickFillCell (reg->descCell); @@ -999,6 +1000,7 @@ xaccDestroySplitRegister (SplitRegister *reg) xaccDestroyPriceCell (reg->tbalanceCell); xaccDestroyQuickFillCell (reg->notesCell); + reg->nullCell = NULL; reg->dateCell = NULL; reg->numCell = NULL; reg->descCell = NULL; diff --git a/src/register/textcell.c b/src/register/textcell.c index 7b635cb9ca..82ac80cfd5 100644 --- a/src/register/textcell.c +++ b/src/register/textcell.c @@ -69,11 +69,6 @@ xaccMallocTextCell (void) void xaccInitTextCell (BasicCell *cell) { - xaccInitBasicCell (cell); - - g_free (cell->value); - cell->value = g_strdup (""); - cell->modify_verify = TextMV; }