From 43745cf5c394a595555c73816d7c6e3fb753811c Mon Sep 17 00:00:00 2001 From: chme Date: Sun, 15 Apr 2018 09:34:12 +0200 Subject: [PATCH] [smartpl.g] Fix memleak in smart playlist parsing with string operators --- src/SMARTPL2SQL.g | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/SMARTPL2SQL.g b/src/SMARTPL2SQL.g index 7f317fd4..8fef34ea 100644 --- a/src/SMARTPL2SQL.g +++ b/src/SMARTPL2SQL.g @@ -131,44 +131,62 @@ expression returns [ pANTLR3_STRING result, pANTLR3_STRING orderby, pANTLR3_STRI | STRTAG INCLUDES STR { pANTLR3_UINT8 val; + char *tmp; + val = $STR.text->toUTF8($STR.text)->chars; val++; val[strlen((const char *)val) - 1] = '\0'; + tmp = sqlite3_mprintf("\%q", (const char *)val); + $result = $STR.text->factory->newRaw($STR.text->factory); $result->append8($result, "f."); $result->appendS($result, $STRTAG.text->toUTF8($STRTAG.text)); $result->append8($result, " LIKE '\%"); - $result->append8($result, sqlite3_mprintf("\%q", (const char *)val)); + $result->append8($result, tmp); $result->append8($result, "\%'"); + + sqlite3_free(tmp); } | STRTAG IS STR { pANTLR3_UINT8 val; + char *tmp; + val = $STR.text->toUTF8($STR.text)->chars; val++; val[strlen((const char *)val) - 1] = '\0'; + tmp = sqlite3_mprintf("\%q", (const char *)val); + $result = $STR.text->factory->newRaw($STR.text->factory); $result->append8($result, "f."); $result->appendS($result, $STRTAG.text->toUTF8($STRTAG.text)); $result->append8($result, " LIKE '"); - $result->append8($result, sqlite3_mprintf("\%q", (const char *)val)); + $result->append8($result, tmp); $result->append8($result, "'"); + + sqlite3_free(tmp); } | STRTAG STARTSWITH STR { pANTLR3_UINT8 val; + char *tmp; + val = $STR.text->toUTF8($STR.text)->chars; val++; val[strlen((const char *)val) - 1] = '\0'; + tmp = sqlite3_mprintf("\%q", (const char *)val); + $result = $STR.text->factory->newRaw($STR.text->factory); $result->append8($result, "f."); $result->appendS($result, $STRTAG.text->toUTF8($STRTAG.text)); $result->append8($result, " LIKE '"); - $result->append8($result, sqlite3_mprintf("\%q", (const char *)val)); + $result->append8($result, tmp); $result->append8($result, "\%'"); + + sqlite3_free(tmp); } | INTTAG INTBOOL INT {