diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-13 10:27:58 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-13 10:27:58 +0300 |
commit | 4c1056b45580fcb687cac656834f42dd9fba4ae8 (patch) | |
tree | d4bc6aaa3749fd0dbcb86f4d3e86d3b44d036b51 /src/preproc.c | |
parent | 967d4d82ef9d10ecd6b32a29f2b3f2743175a268 (diff) | |
download | grecs-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/preproc.c')
-rw-r--r-- | src/preproc.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/src/preproc.c b/src/preproc.c index cd83e2f..ea77506 100644 --- a/src/preproc.c +++ b/src/preproc.c @@ -63,40 +63,39 @@ static size_t putback_size; static size_t putback_max; 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) off = -1; break; } off += strlen(buf + off); - } - while (buf[off - 1] != '\n'); + } while (buf[off - 1] != '\n'); *pbuf = buf; *psize = size; return off; } @@ -160,13 +159,13 @@ next_line() rc = putback_size; putback_size = 0; } 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; } size_t grecs_preproc_fill_buffer(char *buf, size_t size) @@ -661,13 +660,13 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid) default: /* Sub-master */ close (p[1]); 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 { grecs_preproc_run(file_name, grecs_preprocessor); } exit (0); |