代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/flex 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 8a044dbe6d03877c3d8c205ae76be9c41f442237 Mon Sep 17 00:00:00 2001
From: "viktor.shepel" <shepelvictor@bigmir.net>
Date: Tue, 20 Jun 2017 17:03:42 +0300
Subject: [PATCH] filter: memory leak free scanner postprocessing.
**Issue:**
Scanner postprocessing leaks memory during correction of `#line`
directives values and generation of C header file.
**Root cause:**
`filter_fix_linedirs` and `filter_tee_header` functions do not
dispose allocated memory.
**Solution:**
Automatically reclaim affected memory by allocating it on stack
insted of heap. Stack allocation should not be a problem as its
only 512 bytes and there is no recursive calls.
---
src/filter.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/src/filter.c b/src/filter.c
index ed3bfe3..35b80a9 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -230,8 +230,7 @@ int filter_tee_header (struct filter *chain)
* header file at the same time.
*/
- const int readsz = 512;
- char *buf;
+ char buf[512];
int to_cfd = -1;
FILE *to_c = NULL, *to_h = NULL;
bool write_header;
@@ -283,10 +282,7 @@ int filter_tee_header (struct filter *chain)
fprintf (to_c, "m4_define( [[M4_YY_OUTFILE_NAME]],[[%s]])m4_dnl\n",
outfilename ? outfilename : "<stdout>");
- buf = malloc((size_t) readsz);
- if (!buf)
- flexerror(_("malloc failed in filter_tee_header"));
- while (fgets (buf, readsz, stdin)) {
+ while (fgets (buf, sizeof buf, stdin)) {
fputs (buf, to_c);
if (write_header)
fputs (buf, to_h);
@@ -336,8 +332,8 @@ int filter_tee_header (struct filter *chain)
*/
int filter_fix_linedirs (struct filter *chain)
{
- char *buf;
- const size_t readsz = 512;
+ char buf[512];
+ const size_t readsz = sizeof buf;
int lineno = 1;
bool in_gen = true; /* in generated code */
bool last_was_blank = false;
@@ -345,10 +341,6 @@ int filter_fix_linedirs (struct filter *chain)
if (!chain)
return 0;
- buf = malloc(readsz);
- if (!buf)
- flexerror(_("malloc failed in filter_fix_linedirs"));
-
while (fgets (buf, (int) readsz, stdin)) {
regmatch_t m[10];
--
1.8.3.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。