reset optind and fix memory leak in m_ipt/iptables target structure
Subsystems (2)
PATCH 1/1 reset optind and fix memory leak in m_ipt/iptables target structure
According iptables sources for reusing iptables target optind must be reset to
zero, this is important in batch processing. Also if we are using iptables target, we are allocating memory for two temporary variables and inside structure of iptables_target, which must be freed when job done. Also
tflags and used in structure must be reset, to zero for next reuse of structure.
Signed-off-by Denys Fedoryshchenko <[email protected]>
Tested-by Denys Fedoryshchenko <[email protected]>
---
tc/m_ipt.c +14 -1
@@ -277,6 +277,8 @@if (!handle) {fputs (dlerror (), stderr);printf ("\n" ); +free (l_name); +free (new_name);return NULL ; } }
@@ -292,12 +294,16 @@fputs (error, stderr);fprintf (stderr,"\n" );dlclose (handle); +free (l_name); +free (new_name);return NULL ; } } } } +free (l_name); +free (new_name);return m; }
@@ -512,8 +518,15 @@ *argc_p = rargc - iargc; *argv_p = argv; - optind =1 ; + optind =0 ;free_opts (opts); +/* Clear flags if target will be used again */ + m->tflags=0 ; + m->used=0 ; +/* Free allocated memory */ +if (m->t) +free (m->t); +return 0 ;
Quoted 2 lines · Denys Fedoryshchenko
Signed-off-by Denys Fedoryshchenko <[email protected]>Tested-by Denys Fedoryshchenko <[email protected]>
Acked-by Jamal Hadi Salim <[email protected]>
cheers,
jamal