From fdb75d3bf9a3d09f3c95ca0bed0bfb5eaab02684 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 12 Apr 2020 10:53:41 +0200 Subject: [PATCH] Fix memory leak in /ad/ using r_regex api wrongly ##search (#16537) * /ad/ in /bin/ls ate 9 extra MB that was never freed * This is about 400 bytes for each instruction disassembled --- libr/core/casm.c | 6 ++---- libr/util/regex/regcomp.c | 5 ++--- sys/find-regression.sh | 41 --------------------------------------- 3 files changed, 4 insertions(+), 48 deletions(-) delete mode 100755 sys/find-regression.sh diff --git a/libr/core/casm.c b/libr/core/casm.c index 6d3da9c57d..fed7806206 100644 --- a/libr/core/casm.c +++ b/libr/core/casm.c @@ -206,10 +206,8 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6 } else if (!regexp) { matches = strstr (opst, tokens[matchcount]) != NULL; } else { - rx = r_regex_new (tokens[matchcount], ""); - if (r_regex_comp (rx, tokens[matchcount], R_REGEX_EXTENDED|R_REGEX_NOSUB) == 0) { - matches = r_regex_exec (rx, opst, 0, 0, 0) == 0; - } + rx = r_regex_new (tokens[matchcount], "es"); + matches = r_regex_exec (rx, opst, 0, 0, 0) == 0; r_regex_free (rx); } } diff --git a/libr/util/regex/regcomp.c b/libr/util/regex/regcomp.c index bb27f41b37..4123c44d01 100644 --- a/libr/util/regex/regcomp.c +++ b/libr/util/regex/regcomp.c @@ -158,9 +158,8 @@ R_API int r_regex_match (const char *pattern, const char *flags, const char *tex #endif } -R_API RRegex *r_regex_new (const char *pattern, const char *flags) { - RRegex rx, *r; - memset(&rx, 0, sizeof(RRegex)); +R_API RRegex *r_regex_new(const char *pattern, const char *flags) { + RRegex *r, rx = {0}; if (r_regex_comp (&rx, pattern, r_regex_flags (flags))) { return NULL; } diff --git a/sys/find-regression.sh b/sys/find-regression.sh deleted file mode 100755 index 66a7291243..0000000000 --- a/sys/find-regression.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh -NAME=cmd_macros -LAST=`curl -s http://ci.rada.re/job/radare2-regressions/ | \ - perl -ne 's,>,\n,g;print' | \ - perl -ne 'if (/Last build/) { - $str = $_; - $str=~/\(\#(\d+)\)/; - $str = $1; - print $str; - }' -` - -R2R=/tmp/.r2r.txt -R2C=/tmp/.r2c.txt -PREV="" -PR2REV="" -while : ; do - [ ${LAST} -lt 0 ] && break - echo "+ Testing build $LAST..." - curl -s http://ci.rada.re/job/radare2-regressions/${LAST}/consoleText > $R2R - R2B=`grep 'Started by upstream project' $R2R | awk '{print $8 }'` - curl -s http://ci.rada.re/job/radare2/${R2B}/consoleText > $R2C - R2REV=`grep 'Checking out Revision' $R2C | awk '{print $4}'` - echo " - radare2 $R2B = $R2REV" - REV=`grep 'Checking out Revision' $R2R | awk '{print $4}'` - echo " - regression $LAST $REV" - grep ${NAME} $R2R | grep -q XX - if [ $? != 0 ]; then - echo "Passing test found." - echo " + LAST=$LAST..$PLAST" - echo " + RRREV=$REV..$PREV" - echo " + R2REV=$R2REV..$PR2REV" - fi - PREV=$REV - PR2REV=$R2REV - PLAST=$LAST - LAST=$(($LAST-1)) -done - -rm -f $R2R $R2C -