aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-13 10:27:58 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-13 10:27:58 +0300
commit4c1056b45580fcb687cac656834f42dd9fba4ae8 (patch)
treed4bc6aaa3749fd0dbcb86f4d3e86d3b44d036b51 /src
parent967d4d82ef9d10ecd6b32a29f2b3f2743175a268 (diff)
downloadgrecs-4c1056b45580fcb687cac656834f42dd9fba4ae8.tar.gz
grecs-4c1056b45580fcb687cac656834f42dd9fba4ae8.tar.bz2
Fix memory leaks.
* src/grecs-gram.y (slist production): Free ep->data after appending. * src/grecs-lex.l (string_list): Remove. All uses updated. * src/tree.c (grecs_node_free): Free ident. (grecs_tree_process): Fill config_keywords with zeros. * src/grecs.h (grecs_getline): New proto. * src/preproc.c (pp_getline): Rename to grecs_getline, drop static qualifier. Improve initial allocation.
Diffstat (limited to 'src')
-rw-r--r--src/grecs-gram.y5
-rw-r--r--src/grecs-lex.l7
-rw-r--r--src/grecs.h2
-rw-r--r--src/preproc.c31
-rw-r--r--src/tree.c2
5 files changed, 23 insertions, 24 deletions
diff --git a/src/grecs-gram.y b/src/grecs-gram.y
index 8d0adbf..960567e 100644
--- a/src/grecs-gram.y
+++ b/src/grecs-gram.y
@@ -169,8 +169,11 @@ slist : slist0
struct grecs_list_entry *ep;
grecs_line_begin();
- for (ep = $1->head; ep; ep = ep->next)
+ for (ep = $1->head; ep; ep = ep->next) {
grecs_line_add(ep->data, strlen(ep->data));
+ free(ep->data);
+ ep->data = NULL;
+ }
$$ = grecs_line_finish();
grecs_list_free($1);
}
diff --git a/src/grecs-lex.l b/src/grecs-lex.l
index faf6c4c..a3cc7d8 100644
--- a/src/grecs-lex.l
+++ b/src/grecs-lex.l
@@ -49,7 +49,6 @@ grecs_locus_t grecs_current_locus; /* Input file location */
static size_t xlines;
static struct grecs_list *line_acc;
-static struct grecs_list *string_list;
static void multiline_begin(char *);
static void multiline_add(char *);
@@ -185,7 +184,6 @@ grecs_lex_begin(const char *name)
line_acc = grecs_list_create();
line_acc->free_entry = line_acc_free_entry;
- string_list = grecs_list_create();
if (grecs_preprocessor) {
int fd;
@@ -213,9 +211,6 @@ grecs_lex_begin(const char *name)
void
grecs_lex_end(int err)
{
- if (!err)
- string_list->free_entry = NULL;
- grecs_list_free(string_list);
grecs_list_clear(line_acc);
}
@@ -392,7 +387,6 @@ grecs_line_finish()
}
str = grecs_malloc(size + 1);
- grecs_list_append(string_list, str);
for (ep = line_acc->head, p = str; ep; ep = ep->next) {
struct line_acc_entry *ent = ep->data;
char *str = line_acc_ptr(ent);
@@ -417,7 +411,6 @@ ident()
len = strlen(p);
str = grecs_malloc(len + 1);
strcpy(str, p);
- grecs_list_append(string_list, str);
yylval.string = str;
return IDENT;
}
diff --git a/src/grecs.h b/src/grecs.h
index b2ef734..05eeff2 100644
--- a/src/grecs.h
+++ b/src/grecs.h
@@ -250,6 +250,8 @@ struct grecs_symtab *grecs_text_table(void);
void grecs_include_path_setup(const char *dir, ...);
void grecs_include_path_setup_v(char **dirs);
+ssize_t grecs_getline(char **pbuf, size_t *psize, FILE *fp);
+
const char *grecs_data_type_string(enum grecs_data_type type);
void grecs_format_docstring(const char *docstring, unsigned level,
FILE *stream);
diff --git a/src/preproc.c b/src/preproc.c
index cd83e2f..ea77506 100644
--- a/src/preproc.c
+++ b/src/preproc.c
@@ -66,25 +66,25 @@ static int push_source (const char *name, int once);
static int pop_source (void);
static int parse_include (const char *text, int once);
-static ssize_t
-pp_getline(char **pbuf, size_t *psize, FILE *fp)
+ssize_t
+grecs_getline(char **pbuf, size_t *psize, FILE *fp)
{
char *buf = *pbuf;
size_t size = *psize;
ssize_t off = 0;
+ if (!buf) {
+ size = 1;
+ buf = grecs_malloc(size);
+ }
+
do {
if (off == size - 1) {
- if (!buf) {
- size = 1;
- buf = grecs_malloc(size);
- } else {
- size_t nsize = 2 * size;
- if (nsize < size)
- grecs_alloc_die();
- buf = grecs_realloc(buf, nsize);
- size = nsize;
- }
+ size_t nsize = 2 * size;
+ if (nsize < size)
+ grecs_alloc_die();
+ buf = grecs_realloc(buf, nsize);
+ size = nsize;
}
if (!fgets(buf + off, size - off, fp)) {
if (off == 0)
@@ -92,8 +92,7 @@ pp_getline(char **pbuf, size_t *psize, FILE *fp)
break;
}
off += strlen(buf + off);
- }
- while (buf[off - 1] != '\n');
+ } while (buf[off - 1] != '\n');
*pbuf = buf;
*psize = size;
@@ -163,7 +162,7 @@ next_line()
else if (!context_stack)
return 0;
else
- rc = pp_getline(&linebuf, &bufsize, INFILE);
+ rc = grecs_getline(&linebuf, &bufsize, INFILE);
} while (rc == -1 && pop_source() == 0);
return rc;
}
@@ -664,7 +663,7 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid)
fp = fdopen(p[0], "r");
if (grecs_log_setup_hook)
grecs_log_setup_hook();
- while (pp_getline(&buf, &size, fp) > 0)
+ while (grecs_getline(&buf, &size, fp) > 0)
grecs_error(NULL, 0, "%s", buf);
}
} else {
diff --git a/src/tree.c b/src/tree.c
index 770f660..3419de7 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -194,6 +194,7 @@ grecs_node_free(struct grecs_node *node)
default:
grecs_value_free(node->v.value);
}
+ grecs_free(node->ident);
grecs_free(node);
}
@@ -862,6 +863,7 @@ grecs_tree_process(struct grecs_node *node, struct grecs_keyword *kwd)
struct nodeproc_closure clos;
struct grecs_keyword config_keywords;
+ memset(&config_keywords, 0, sizeof(config_keywords));
config_keywords.kwd = kwd;
clos.cursect = &config_keywords;
clos.sections = grecs_list_create();

Return to:

Send suggestions and report system problems to the System administrator.