]> granicus.if.org Git - graphviz/commitdiff
fix memory leak in label construction
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 10 Nov 2020 04:15:00 +0000 (20:15 -0800)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 23 Jan 2021 02:03:11 +0000 (18:03 -0800)
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
lib/common/shapes.c

index 0618bf5ebd1bdad8b85eaa751d42e727b860c14d..129dec5190019ae77668dbbd742407fc1c0c6e98 100644 (file)
@@ -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
index 6641a6ca01a4ed142de86d2f30fb1246d90bcd79..6fc4b7e77534f5f4682a3c5c4c50a88a60d5d20a 100644 (file)
@@ -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);