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 | |||
@@ -66,25 +66,25 @@ static int push_source (const char *name, int once); | |||
66 | static int pop_source (void); | 66 | static int pop_source (void); |
67 | static int parse_include (const char *text, int once); | 67 | static int parse_include (const char *text, int once); |
68 | 68 | ||
69 | static ssize_t | 69 | ssize_t |
70 | pp_getline(char **pbuf, size_t *psize, FILE *fp) | 70 | grecs_getline(char **pbuf, size_t *psize, FILE *fp) |
71 | { | 71 | { |
72 | char *buf = *pbuf; | 72 | char *buf = *pbuf; |
73 | size_t size = *psize; | 73 | size_t size = *psize; |
74 | ssize_t off = 0; | 74 | ssize_t off = 0; |
75 | 75 | ||
76 | if (!buf) { | ||
77 | size = 1; | ||
78 | buf = grecs_malloc(size); | ||
79 | } | ||
80 | |||
76 | do { | 81 | do { |
77 | if (off == size - 1) { | 82 | if (off == size - 1) { |
78 | if (!buf) { | 83 | size_t nsize = 2 * size; |
79 | size = 1; | 84 | if (nsize < size) |
80 | buf = grecs_malloc(size); | 85 | grecs_alloc_die(); |
81 | } else { | 86 | buf = grecs_realloc(buf, nsize); |
82 | size_t nsize = 2 * size; | 87 | size = nsize; |
83 | if (nsize < size) | ||
84 | grecs_alloc_die(); | ||
85 | buf = grecs_realloc(buf, nsize); | ||
86 | size = nsize; | ||
87 | } | ||
88 | } | 88 | } |
89 | if (!fgets(buf + off, size - off, fp)) { | 89 | if (!fgets(buf + off, size - off, fp)) { |
90 | if (off == 0) | 90 | if (off == 0) |
@@ -92,8 +92,7 @@ pp_getline(char **pbuf, size_t *psize, FILE *fp) | |||
92 | break; | 92 | break; |
93 | } | 93 | } |
94 | off += strlen(buf + off); | 94 | off += strlen(buf + off); |
95 | } | 95 | } while (buf[off - 1] != '\n'); |
96 | while (buf[off - 1] != '\n'); | ||
97 | 96 | ||
98 | *pbuf = buf; | 97 | *pbuf = buf; |
99 | *psize = size; | 98 | *psize = size; |
@@ -163,7 +162,7 @@ next_line() | |||
163 | else if (!context_stack) | 162 | else if (!context_stack) |
164 | return 0; | 163 | return 0; |
165 | else | 164 | else |
166 | rc = pp_getline(&linebuf, &bufsize, INFILE); | 165 | rc = grecs_getline(&linebuf, &bufsize, INFILE); |
167 | } while (rc == -1 && pop_source() == 0); | 166 | } while (rc == -1 && pop_source() == 0); |
168 | return rc; | 167 | return rc; |
169 | } | 168 | } |
@@ -664,7 +663,7 @@ grecs_preproc_extrn_start(const char *file_name, pid_t *ppid) | |||
664 | fp = fdopen(p[0], "r"); | 663 | fp = fdopen(p[0], "r"); |
665 | if (grecs_log_setup_hook) | 664 | if (grecs_log_setup_hook) |
666 | grecs_log_setup_hook(); | 665 | grecs_log_setup_hook(); |
667 | while (pp_getline(&buf, &size, fp) > 0) | 666 | while (grecs_getline(&buf, &size, fp) > 0) |
668 | grecs_error(NULL, 0, "%s", buf); | 667 | grecs_error(NULL, 0, "%s", buf); |
669 | } | 668 | } |
670 | } else { | 669 | } else { |