Skip to content

Commit

Permalink
Dynamic: Avoid copying of constant strings without backslash escapes
Browse files Browse the repository at this point in the history
It appears OK for dynamic_Demangle() to return a pointer to its input
string, rather than to a copy, because the only uses are:

1. In dynamic_parser.c, on pointers to config file lines, and we pre-read
the entire config file (and includes) into a linked list of separate line
structs, and we don't de-allocate those.
2. In dynamic_compiler.c: #define APP_CFUNC(N), we only pass the returned
pointer to dyna_helper_appendn(), which does not store the pointer.

Mostly fixes #5465 (memory leak)
  • Loading branch information
solardiz committed Apr 28, 2024
1 parent 56f7571 commit a51fd51
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/dynamic_utils.c
Expand Up @@ -101,13 +101,23 @@ static int ishexdigit(char c) {
return 1;
return 0;
}
// Only called at load time, so does not have to be overly optimal

// Was only called at load time, so did not have to be overly optimal and could
// leak memory.
// Now is also called as fallback by the RDP dynamic compiler format, so should
// avoid leaking memory, but in non-trivial cases still does.
char *dynamic_Demangle(char *Line, int *Len)
{
char *tmp, *cp, *cp2, digits[3];
if (!Line || !strlen(Line)) {
if (Len) *Len = 0;
return str_alloc_copy("");
if (!Line) {
if (Len)
*Len = 0;
return "";
}
if (!strchr(Line, '\\')) {
if (Len)
*Len = strlen(Line);
return Line;
}
tmp = str_alloc_copy(Line);
cp = tmp;
Expand Down

0 comments on commit a51fd51

Please sign in to comment.