Commit bb21fc5e authored by Vysheng's avatar Vysheng

Fixed memory leak

parent 2e0a7fda
...@@ -135,6 +135,20 @@ static struct paramed_type *paramed_type_dup (struct paramed_type *P) { ...@@ -135,6 +135,20 @@ static struct paramed_type *paramed_type_dup (struct paramed_type *P) {
return R; return R;
} }
void tgl_paramed_type_free (struct paramed_type *P) {
if (ODDP (P)) { return; }
if (P->type->params_num) {
int i;
for (i = 0; i < P->type->params_num; i++) {
tgl_paramed_type_free (P->params[i]);
}
free (P->params);
}
free (P->type->id);
free (P->type);
free (P);
}
static void print_offset (void) { static void print_offset (void) {
int i; int i;
for (i = 0; i < multiline_offset; i++) { for (i = 0; i < multiline_offset; i++) {
...@@ -277,6 +291,23 @@ static void local_next_token (void) { ...@@ -277,6 +291,23 @@ static void local_next_token (void) {
} }
} }
#define MAX_FVARS 100
static struct paramed_type *fvars[MAX_FVARS];
static int fvars_pos;
void add_var_to_be_freed (struct paramed_type *P) {
assert (fvars_pos < MAX_FVARS);
fvars[fvars_pos ++] = P;
}
void free_vars_to_be_freed (void) {
int i;
for (i = 0; i < fvars_pos; i++) {
tgl_paramed_type_free (fvars[i]);
}
fvars_pos = 0;
}
int tglf_extf_autocomplete (const char *text, int text_len, int index, char **R, char *data, int data_len) { int tglf_extf_autocomplete (const char *text, int text_len, int index, char **R, char *data, int data_len) {
if (index == -1) { if (index == -1) {
buffer_pos = data; buffer_pos = data;
...@@ -284,6 +315,7 @@ int tglf_extf_autocomplete (const char *text, int text_len, int index, char **R, ...@@ -284,6 +315,7 @@ int tglf_extf_autocomplete (const char *text, int text_len, int index, char **R,
autocomplete_mode = 0; autocomplete_mode = 0;
local_next_token (); local_next_token ();
autocomplete_function_any (); autocomplete_function_any ();
free_vars_to_be_freed ();
} }
if (autocomplete_mode == 0) { return -1; } if (autocomplete_mode == 0) { return -1; }
int len = strlen (text); int len = strlen (text);
......
...@@ -41,6 +41,8 @@ struct paramed_type { ...@@ -41,6 +41,8 @@ struct paramed_type {
#define INT2PTR(x) (void *)(long)(((long)x) * 2 + 1) #define INT2PTR(x) (void *)(long)(((long)x) * 2 + 1)
#define PTR2INT(x) ((((long)x) - 1) / 2) #define PTR2INT(x) ((((long)x) - 1) / 2)
void tgl_paramed_type_free (struct paramed_type *P);
#include "auto/auto-header.h" #include "auto/auto-header.h"
#endif #endif
...@@ -713,6 +713,7 @@ int gen_field_autocomplete_excl (struct arg *arg, int *vars, int num, int from_f ...@@ -713,6 +713,7 @@ int gen_field_autocomplete_excl (struct arg *arg, int *vars, int num, int from_f
assert (t == NODE_TYPE_TYPE || t == NODE_TYPE_VAR_TYPE); assert (t == NODE_TYPE_TYPE || t == NODE_TYPE_VAR_TYPE);
printf ("%sstruct paramed_type *field%d = autocomplete_function_any ();\n", offset, num); printf ("%sstruct paramed_type *field%d = autocomplete_function_any ();\n", offset, num);
printf ("%sif (!field%d) { return 0; }\n", offset, num); printf ("%sif (!field%d) { return 0; }\n", offset, num);
printf ("%sadd_var_to_be_freed (field%d);\n", offset, num);
static char s[20]; static char s[20];
sprintf (s, "field%d", num); sprintf (s, "field%d", num);
gen_uni_skip (arg->type, s, vars, 1, 1); gen_uni_skip (arg->type, s, vars, 1, 1);
......
...@@ -3475,6 +3475,7 @@ static int ext_query_on_answer (struct query *q UU) { ...@@ -3475,6 +3475,7 @@ static int ext_query_on_answer (struct query *q UU) {
char *buf = tglf_extf_fetch (q->type); char *buf = tglf_extf_fetch (q->type);
((void (*)(void *, int, char *))q->callback) (q->callback_extra, 1, buf); ((void (*)(void *, int, char *))q->callback) (q->callback_extra, 1, buf);
} }
tgl_paramed_type_free (q->type);
return 0; return 0;
} }
......
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