Fixed memory leaks and uninitialized values.

This commit is contained in:
EvilPudding
2016-02-24 20:15:47 +00:00
parent 0417ed63a8
commit bda6fa9d30
3 changed files with 5 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
CC = gcc CC = gcc
CCFLAGS = -ansi -Wall -Wshadow -O2 CCFLAGS = -ansi -Wall -Wshadow -O2
LFLAGS = -lm LFLAGS = -lm

View File

@@ -63,6 +63,7 @@ static te_expr *new_expr(const int type, const te_expr *members[]) {
int member_count = te_get_arity(type); int member_count = te_get_arity(type);
size_t member_size = sizeof(te_expr*) * member_count; size_t member_size = sizeof(te_expr*) * member_count;
te_expr *ret = malloc(sizeof(te_expr) + member_size); te_expr *ret = malloc(sizeof(te_expr) + member_size);
ret->member_count = member_count;
if(!members) { if(!members) {
memset(ret->members, 0, member_size); memset(ret->members, 0, member_size);
} else { } else {

View File

@@ -42,13 +42,13 @@ typedef double (*te_fun7)(double, double, double, double, double, double, double
typedef union typedef union
{ {
te_fun0 f0; te_fun1 f1; te_fun2 f2; te_fun3 f3; te_fun4 f4; te_fun5 f5; te_fun6 f6; te_fun7 f7; te_fun0 f0; te_fun1 f1; te_fun2 f2; te_fun3 f3; te_fun4 f4; te_fun5 f5; te_fun6 f6; te_fun7 f7;
} te_fun; } te_fun;
typedef struct te_expr { typedef struct te_expr {
int type; int type;
union {double value; const double *bound; te_fun fun; }; union {double value; const double *bound; te_fun fun; };
int member_count; int member_count;
struct te_expr *members[]; struct te_expr *members[];
} te_expr; } te_expr;