Skip to content

Commit 985ec95

Browse files
authored
Fix: close magic cookie (#2093)
This produces a leak when sending a results. Scripts like host_details.nasl produces many results and this ends with leaking a huge amount of memory
1 parent 09a3b52 commit 985ec95

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

misc/plugutils.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,7 @@ static int
664664
is_utf8_encoded (const char *filename)
665665
{
666666
magic_t magic_cookie = magic_open (MAGIC_MIME_ENCODING);
667+
int ret = 0;
667668
if (!magic_cookie)
668669
{
669670
g_warning ("%s: It is not possible initialize magic db", __func__);
@@ -673,20 +674,24 @@ is_utf8_encoded (const char *filename)
673674
{
674675
g_warning ("%s: It was not possible to load the default magic db",
675676
__func__);
676-
return -1;
677+
ret = -1;
678+
goto magic_ret;
677679
}
678680
const char *file_encoding = magic_file (magic_cookie, filename);
679681
if (!file_encoding)
680682
{
681683
g_warning ("%s: It was not possible to identify the file encoding for %s",
682684
__func__, filename);
683-
return -1;
685+
ret = -1;
686+
goto magic_ret;
684687
}
685688

686689
if (g_strstr_len (file_encoding, strlen (file_encoding), "utf-8"))
687-
return 1;
690+
ret = 1;
688691

689-
return 0;
692+
magic_ret:
693+
magic_close (magic_cookie);
694+
return ret;
690695
}
691696

692697
/**

0 commit comments

Comments
 (0)