GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

Commit c8fc4123 authored by Morten Welinder's avatar Morten Welinder

Plug leaks.

parent 02cbd16d
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.
(alloc_register): Ditto.
(dump_tree): Fix reference to variable cell.
......
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.
(alloc_register): Ditto.
(dump_tree): Fix reference to variable cell.
......
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.
(alloc_register): Ditto.
(dump_tree): Fix reference to variable cell.
......
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.
(alloc_register): Ditto.
(dump_tree): Fix reference to variable cell.
......
......@@ -43,32 +43,9 @@ expr_parse_string (const char *expr, Sheet *sheet, int col, int row,
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 *
expr_tree_new ()
expr_tree_new (void)
{
ExprTree *ans = g_new (ExprTree, 1);
if (!ans) return NULL;
......@@ -88,26 +65,32 @@ expr_tree_ref (ExprTree *tree)
g_return_if_fail (tree != NULL);
g_return_if_fail (tree->ref_count > 0);
do_expr_tree_ref (tree);
tree->ref_count++;
}
static void
do_expr_tree_unref (ExprTree *tree)
{
tree->ref_count--;
if (--tree->ref_count > 0)
return;
switch (tree->oper){
case OPER_VAR:
break;
case OPER_CONSTANT:
if (tree->ref_count == 0)
value_release (tree->u.constant);
value_release (tree->u.constant);
break;
case OPER_FUNCALL:
if (tree->ref_count == 0)
symbol_unref (tree->u.function.symbol);
case OPER_FUNCALL: {
GList *l;
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;
}
case OPER_ANY_BINARY:
do_expr_tree_unref (tree->u.binary.value_a);
......@@ -119,10 +102,15 @@ do_expr_tree_unref (ExprTree *tree)
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
expr_tree_unref (ExprTree *tree)
{
......@@ -183,6 +171,7 @@ value_release (Value *value)
g_free (value->v.array.vals [i]);
g_free (value->v.array.vals);
break;
}
case VALUE_CELLRANGE:
......@@ -276,12 +265,14 @@ value_str (const char *str)
}
Value *
value_cellrange (CellRef *a, CellRef *b)
value_cellrange (const CellRef *a, const CellRef *b)
{
Value *v = g_new (Value, 1);
v->type = VALUE_CELLRANGE;
memcpy (&v->v.cell_range.cell_a, a, sizeof(CellRef));
memcpy (&v->v.cell_range.cell_b, b, sizeof(CellRef));
v->v.cell_range.cell_a = *a;
v->v.cell_range.cell_b = *b;
return v;
}
......
......@@ -163,7 +163,7 @@ ExprTree *expr_tree_relocate (ExprTree *expr, int col_diff, int row_diff);
char *expr_decode_tree (ExprTree *tree, Sheet *sheet,
int col, int row);
ExprTree *expr_tree_new ();
ExprTree *expr_tree_new (void);
void expr_tree_ref (ExprTree *tree);
void expr_tree_unref (ExprTree *tree);
......@@ -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_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);
char *value_string (const Value *value);
......
......@@ -661,6 +661,8 @@ split_time (gdouble number)
secs -= tm.tm_min * 60;
tm.tm_sec = floor (secs);
g_date_free (date);
return &tm;
}
......
......@@ -141,18 +141,13 @@ exp: NUMBER { $$ = $1 }
}
| cellref ':' cellref {
CellRef a, b;
a = $1->u.ref;
b = $3->u.ref;
$$ = p_new (ExprTree);
$$->ref_count = 1;
$$->oper = OPER_CONSTANT;
$$->u.constant = v_new ();
$$->u.constant->type = VALUE_CELLRANGE;
$$->u.constant->v.cell_range.cell_a = a;
$$->u.constant->v.cell_range.cell_b = b;
$$->u.constant->v.cell_range.cell_a = $1->u.ref;
$$->u.constant->v.cell_range.cell_b = $3->u.ref;
forget_tree ($1);
forget_tree ($3);
......@@ -230,7 +225,7 @@ return_cellref (char *p)
/* Ok, parsed successfully, create the return value */
e = p_new (ExprTree);
e->ref_count = 1;
e->oper = OPER_VAR;
ref = &e->u.ref;
......@@ -249,7 +244,7 @@ return_cellref (char *p)
ref->col_relative = col_relative;
ref->row_relative = row_relative;
ref->sheet = parser_sheet;
yylval.tree = e;
return CELLREF;
......@@ -624,6 +619,7 @@ forget (AllocType type, void *data)
if (a_info->type == type && a_info->data == data){
alloc_list = g_list_remove_link (alloc_list, l);
g_list_free_1 (l);
g_free (a_info);
return;
}
}
......@@ -638,8 +634,8 @@ forget_glist (GList *list)
static void
forget_tree (ExprTree *tree)
{
expr_tree_unref (tree);
forget (ALLOC_BUFFER, tree);
expr_tree_unref (tree);
}
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