From 8ffdeb249a14784435ea24a6d1b110681e381c6b Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Mon, 9 Nov 2020 20:15:00 -0800 Subject: [PATCH] fix memory leak in label construction make_label() internally strdups its input, so this extra allocation was simply being lost. This was observable using an ASan-instrumented build and the command `dot -Tsvg -o /dev/null ./rtest/share/alf.gv`: Direct leak of 121 byte(s) in 12 object(s) allocated from: #0 0x7fd2541bf810 in strdup (/lib/x86_64-linux-gnu/libasan.so.5+0x3a810) #1 0x7fd25404a955 in parse_reclbl /tmp/tmp.bXYbsH93VJ/graphviz/lib/common/shapes.c:3314 #2 0x7fd25404a5eb in parse_reclbl /tmp/tmp.bXYbsH93VJ/graphviz/lib/common/shapes.c:3292 #3 0x7fd25404ca5f in record_init /tmp/tmp.bXYbsH93VJ/graphviz/lib/common/shapes.c:3556 #4 0x7fd25405966a in common_init_node /tmp/tmp.bXYbsH93VJ/graphviz/lib/common/utils.c:658 #5 0x7fd24fc78a01 in dot_init_node /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:40 #6 0x7fd24fc79522 in dot_init_node_edge /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:81 #7 0x7fd24fc7ad61 in dotLayout /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:295 #8 0x7fd24fc7c4b9 in doDot /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:450 #9 0x7fd24fc7ca94 in dot_layout /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:496 #10 0x7fd253f7673d in gvLayoutJobs /tmp/tmp.bXYbsH93VJ/graphviz/lib/gvc/gvlayout.c:85 #11 0x55a9961b3960 in main /tmp/tmp.bXYbsH93VJ/graphviz/cmd/dot/dot.c:132 #12 0x7fd253d2309a in __libc_start_main ../csu/libc-start.c:308 Direct leak of 118 byte(s) in 19 object(s) allocated from: #0 0x7fd2541bf810 in strdup (/lib/x86_64-linux-gnu/libasan.so.5+0x3a810) #1 0x7fd25404a955 in parse_reclbl /tmp/tmp.bXYbsH93VJ/graphviz/lib/common/shapes.c:3314 #2 0x7fd25404ca5f in record_init /tmp/tmp.bXYbsH93VJ/graphviz/lib/common/shapes.c:3556 #3 0x7fd25405966a in common_init_node /tmp/tmp.bXYbsH93VJ/graphviz/lib/common/utils.c:658 #4 0x7fd24fc78a01 in dot_init_node /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:40 #5 0x7fd24fc79522 in dot_init_node_edge /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:81 #6 0x7fd24fc7ad61 in dotLayout /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:295 #7 0x7fd24fc7c4b9 in doDot /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:450 #8 0x7fd24fc7ca94 in dot_layout /tmp/tmp.bXYbsH93VJ/graphviz/lib/dotgen/dotinit.c:496 #9 0x7fd253f7673d in gvLayoutJobs /tmp/tmp.bXYbsH93VJ/graphviz/lib/gvc/gvlayout.c:85 #10 0x55a9961b3960 in main /tmp/tmp.bXYbsH93VJ/graphviz/cmd/dot/dot.c:132 #11 0x7fd253d2309a in __libc_start_main ../csu/libc-start.c:308 --- CHANGELOG.md | 3 +++ lib/common/shapes.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0618bf5eb..129dec519 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - CentOS/RHEL 6 is no longer supported +### Fixed +- memory leak in label construction + ## [2.46.0] - 2021-01-18 ### Added diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 6641a6ca0..6fc4b7e77 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -3311,7 +3311,7 @@ static field_t *parse_reclbl(node_t * n, int LR, int flag, char *text) tsp--; *tsp = '\000'; fp->lp = - make_label((void *) n, strdup(text), + make_label((void *) n, text, (lbl->html ? LT_HTML : LT_NONE), lbl->fontsize, lbl->fontname, lbl->fontcolor); -- 2.40.0