Commit c8fc4123 authored by Morten Welinder's avatar Morten Welinder
Browse files

Plug leaks.

parent 02cbd16d
1999-05-03 Morten Welinder <terra@diku.dk> 1999-05-03 Morten Welinder <terra@diku.dk>
* src/format.c (split_time): Fix leak.
* src/parser.y (forget): Fix leak.
* src/expr.c (do_expr_tree_ref): Delete.
(expr_tree_ref): Just increase the ref-count.
(do_expr_tree_unref): Properly decrease all the way.
(expr_tree_new): Fix prototype.
(value_release): Add "break".
(value_cellrange): Make args const. Don't use memcpy call.
* src/parser.y (v_new): Fix type. * src/parser.y (v_new): Fix type.
(alloc_register): Ditto. (alloc_register): Ditto.
(dump_tree): Fix reference to variable cell. (dump_tree): Fix reference to variable cell.
......
1999-05-03 Morten Welinder <terra@diku.dk> 1999-05-03 Morten Welinder <terra@diku.dk>
* src/format.c (split_time): Fix leak.
* src/parser.y (forget): Fix leak.
* src/expr.c (do_expr_tree_ref): Delete.
(expr_tree_ref): Just increase the ref-count.
(do_expr_tree_unref): Properly decrease all the way.
(expr_tree_new): Fix prototype.
(value_release): Add "break".
(value_cellrange): Make args const. Don't use memcpy call.
* src/parser.y (v_new): Fix type. * src/parser.y (v_new): Fix type.
(alloc_register): Ditto. (alloc_register): Ditto.
(dump_tree): Fix reference to variable cell. (dump_tree): Fix reference to variable cell.
......
1999-05-03 Morten Welinder <terra@diku.dk> 1999-05-03 Morten Welinder <terra@diku.dk>
* src/format.c (split_time): Fix leak.
* src/parser.y (forget): Fix leak.
* src/expr.c (do_expr_tree_ref): Delete.
(expr_tree_ref): Just increase the ref-count.
(do_expr_tree_unref): Properly decrease all the way.
(expr_tree_new): Fix prototype.
(value_release): Add "break".
(value_cellrange): Make args const. Don't use memcpy call.
* src/parser.y (v_new): Fix type. * src/parser.y (v_new): Fix type.
(alloc_register): Ditto. (alloc_register): Ditto.
(dump_tree): Fix reference to variable cell. (dump_tree): Fix reference to variable cell.
......
1999-05-03 Morten Welinder <terra@diku.dk> 1999-05-03 Morten Welinder <terra@diku.dk>
* src/format.c (split_time): Fix leak.
* src/parser.y (forget): Fix leak.
* src/expr.c (do_expr_tree_ref): Delete.
(expr_tree_ref): Just increase the ref-count.
(do_expr_tree_unref): Properly decrease all the way.
(expr_tree_new): Fix prototype.
(value_release): Add "break".
(value_cellrange): Make args const. Don't use memcpy call.
* src/parser.y (v_new): Fix type. * src/parser.y (v_new): Fix type.
(alloc_register): Ditto. (alloc_register): Ditto.
(dump_tree): Fix reference to variable cell. (dump_tree): Fix reference to variable cell.
......
...@@ -43,32 +43,9 @@ expr_parse_string (const char *expr, Sheet *sheet, int col, int row, ...@@ -43,32 +43,9 @@ expr_parse_string (const char *expr, Sheet *sheet, int col, int row,
return NULL; return NULL;
} }
static void
do_expr_tree_ref (ExprTree *tree)
{
g_return_if_fail (tree != NULL);
g_return_if_fail (tree->ref_count > 0);
tree->ref_count++;
switch (tree->oper){
case OPER_VAR:
case OPER_CONSTANT:
case OPER_FUNCALL:
break;
case OPER_ANY_BINARY:
do_expr_tree_ref (tree->u.binary.value_a);
do_expr_tree_ref (tree->u.binary.value_b);
break;
case OPER_ANY_UNARY:
do_expr_tree_ref (tree->u.value);
break;
}
}
ExprTree * ExprTree *
expr_tree_new () expr_tree_new (void)
{ {
ExprTree *ans = g_new (ExprTree, 1); ExprTree *ans = g_new (ExprTree, 1);
if (!ans) return NULL; if (!ans) return NULL;
...@@ -88,26 +65,32 @@ expr_tree_ref (ExprTree *tree) ...@@ -88,26 +65,32 @@ expr_tree_ref (ExprTree *tree)
g_return_if_fail (tree != NULL); g_return_if_fail (tree != NULL);
g_return_if_fail (tree->ref_count > 0); g_return_if_fail (tree->ref_count > 0);
do_expr_tree_ref (tree); tree->ref_count++;
} }
static void static void
do_expr_tree_unref (ExprTree *tree) do_expr_tree_unref (ExprTree *tree)
{ {
tree->ref_count--; if (--tree->ref_count > 0)
return;
switch (tree->oper){ switch (tree->oper){
case OPER_VAR: case OPER_VAR:
break; break;
case OPER_CONSTANT: case OPER_CONSTANT:
if (tree->ref_count == 0) value_release (tree->u.constant);
value_release (tree->u.constant);
break; break;
case OPER_FUNCALL: case OPER_FUNCALL: {
if (tree->ref_count == 0) GList *l;
symbol_unref (tree->u.function.symbol);
for (l = tree->u.function.arg_list; l; l = l->next)
do_expr_tree_unref (l->data);
g_list_free (tree->u.function.arg_list);
symbol_unref (tree->u.function.symbol);
break; break;
}
case OPER_ANY_BINARY: case OPER_ANY_BINARY:
do_expr_tree_unref (tree->u.binary.value_a); do_expr_tree_unref (tree->u.binary.value_a);
...@@ -119,10 +102,15 @@ do_expr_tree_unref (ExprTree *tree) ...@@ -119,10 +102,15 @@ do_expr_tree_unref (ExprTree *tree)
break; break;
} }
if (tree->ref_count == 0) g_free (tree);
g_free (tree);
} }
/*
* expr_tree_unref:
* Decrements the ref_count for part of a tree. (All trees are expected
* to have been created with a ref-count of one, so when we hit zero, we
* go down over the tree and unref the tree and its leaves stuff.)
*/
void void
expr_tree_unref (ExprTree *tree) expr_tree_unref (ExprTree *tree)
{ {
...@@ -183,6 +171,7 @@ value_release (Value *value) ...@@ -183,6 +171,7 @@ value_release (Value *value)
g_free (value->v.array.vals [i]); g_free (value->v.array.vals [i]);
g_free (value->v.array.vals); g_free (value->v.array.vals);
break;
} }
case VALUE_CELLRANGE: case VALUE_CELLRANGE:
...@@ -276,12 +265,14 @@ value_str (const char *str) ...@@ -276,12 +265,14 @@ value_str (const char *str)
} }
Value * Value *
value_cellrange (CellRef *a, CellRef *b) value_cellrange (const CellRef *a, const CellRef *b)
{ {
Value *v = g_new (Value, 1); Value *v = g_new (Value, 1);
v->type = VALUE_CELLRANGE; v->type = VALUE_CELLRANGE;
memcpy (&v->v.cell_range.cell_a, a, sizeof(CellRef)); v->v.cell_range.cell_a = *a;
memcpy (&v->v.cell_range.cell_b, b, sizeof(CellRef)); v->v.cell_range.cell_b = *b;
return v; return v;
} }
......
...@@ -163,7 +163,7 @@ ExprTree *expr_tree_relocate (ExprTree *expr, int col_diff, int row_diff); ...@@ -163,7 +163,7 @@ ExprTree *expr_tree_relocate (ExprTree *expr, int col_diff, int row_diff);
char *expr_decode_tree (ExprTree *tree, Sheet *sheet, char *expr_decode_tree (ExprTree *tree, Sheet *sheet,
int col, int row); int col, int row);
ExprTree *expr_tree_new (); ExprTree *expr_tree_new (void);
void expr_tree_ref (ExprTree *tree); void expr_tree_ref (ExprTree *tree);
void expr_tree_unref (ExprTree *tree); void expr_tree_unref (ExprTree *tree);
...@@ -195,7 +195,7 @@ Value *value_array_new (guint width, guint height); ...@@ -195,7 +195,7 @@ Value *value_array_new (guint width, guint height);
void value_array_resize (Value *v, guint width, guint height); void value_array_resize (Value *v, guint width, guint height);
void value_array_copy_to (Value *dest, const Value *src); void value_array_copy_to (Value *dest, const Value *src);
Value *value_cellrange (CellRef *a, CellRef *b); Value *value_cellrange (const CellRef *a, const CellRef *b);
void value_dump (Value *value); void value_dump (Value *value);
char *value_string (const Value *value); char *value_string (const Value *value);
......
...@@ -661,6 +661,8 @@ split_time (gdouble number) ...@@ -661,6 +661,8 @@ split_time (gdouble number)
secs -= tm.tm_min * 60; secs -= tm.tm_min * 60;
tm.tm_sec = floor (secs); tm.tm_sec = floor (secs);
g_date_free (date);
return &tm; return &tm;
} }
......
...@@ -141,18 +141,13 @@ exp: NUMBER { $$ = $1 } ...@@ -141,18 +141,13 @@ exp: NUMBER { $$ = $1 }
} }
| cellref ':' cellref { | cellref ':' cellref {
CellRef a, b;
a = $1->u.ref;
b = $3->u.ref;
$$ = p_new (ExprTree); $$ = p_new (ExprTree);
$$->ref_count = 1; $$->ref_count = 1;
$$->oper = OPER_CONSTANT; $$->oper = OPER_CONSTANT;
$$->u.constant = v_new (); $$->u.constant = v_new ();
$$->u.constant->type = VALUE_CELLRANGE; $$->u.constant->type = VALUE_CELLRANGE;
$$->u.constant->v.cell_range.cell_a = a; $$->u.constant->v.cell_range.cell_a = $1->u.ref;
$$->u.constant->v.cell_range.cell_b = b; $$->u.constant->v.cell_range.cell_b = $3->u.ref;
forget_tree ($1); forget_tree ($1);
forget_tree ($3); forget_tree ($3);
...@@ -230,7 +225,7 @@ return_cellref (char *p) ...@@ -230,7 +225,7 @@ return_cellref (char *p)
/* Ok, parsed successfully, create the return value */ /* Ok, parsed successfully, create the return value */
e = p_new (ExprTree); e = p_new (ExprTree);
e->ref_count = 1; e->ref_count = 1;
e->oper = OPER_VAR; e->oper = OPER_VAR;
ref = &e->u.ref; ref = &e->u.ref;
...@@ -249,7 +244,7 @@ return_cellref (char *p) ...@@ -249,7 +244,7 @@ return_cellref (char *p)
ref->col_relative = col_relative; ref->col_relative = col_relative;
ref->row_relative = row_relative; ref->row_relative = row_relative;
ref->sheet = parser_sheet; ref->sheet = parser_sheet;
yylval.tree = e; yylval.tree = e;
return CELLREF; return CELLREF;
...@@ -624,6 +619,7 @@ forget (AllocType type, void *data) ...@@ -624,6 +619,7 @@ forget (AllocType type, void *data)
if (a_info->type == type && a_info->data == data){ if (a_info->type == type && a_info->data == data){
alloc_list = g_list_remove_link (alloc_list, l); alloc_list = g_list_remove_link (alloc_list, l);
g_list_free_1 (l); g_list_free_1 (l);
g_free (a_info);
return; return;
} }
} }
...@@ -638,8 +634,8 @@ forget_glist (GList *list) ...@@ -638,8 +634,8 @@ forget_glist (GList *list)
static void static void
forget_tree (ExprTree *tree) forget_tree (ExprTree *tree)
{ {
expr_tree_unref (tree);
forget (ALLOC_BUFFER, tree); forget (ALLOC_BUFFER, tree);
expr_tree_unref (tree);
} }
void void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment