summaryrefslogtreecommitdiffabout
path: root/src/preproc.c
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-13 07:27:58 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-05-13 07:27:58 (GMT)
commit4c1056b45580fcb687cac656834f42dd9fba4ae8 (patch) (side-by-side diff)
treed4bc6aaa3749fd0dbcb86f4d3e86d3b44d036b51 /src/preproc.c
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/preproc.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/preproc.c31
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
@@ -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 {

Return to:

Send suggestions and report system problems to the System administrator.