Fix covscan-detected issues
Phil Sutter
reviewercover Fix covscan-detected issues
These are merely memleaks in error paths related to multi device support in flowtables and netdev family chains.
Phil Sutter (4):
flowtable: Fix memleak in error path of nftnl_flowtable_parse_devs()
chain: Fix memleak in error path of nftnl_chain_parse_devs()
flowtable: Correctly check realloc() call
chain: Correctly check realloc() call
src/chain.c | 12 ++++++------ src/flowtable.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.24.0
Phil Sutter
reviewerPATCH 1/4 flowtable: Fix memleak in error path of nftnl_flowtable_parse_devs()
In error case, allocated dev_array is not freed.
--- src/flowtable.c | 1 + 1 file changed, 1 insertion(+)
src/flowtable.c +1 -0
@@ -419,6 +419,7 @@ static int nftnl_flowtable_parse_devs(struct nlattr *nest, err:while (len--)xfree (dev_array[len]); +xfree (dev_array);return -1 ; }
Signature · 1 line
2.24.0
Phil Sutter
reviewerPATCH 2/4 chain: Fix memleak in error path of nftnl_chain_parse_devs()
In reply to Phil SutterIn error case, dev_array is not freed when it should.
--- src/chain.c | 1 + 1 file changed, 1 insertion(+)
src/chain.c +1 -0
@@ -636,6 +636,7 @@ static int nftnl_chain_parse_devs(struct nlattr *nest, struct nftnl_chain *c) err:while (len--)xfree (dev_array[len]); +xfree (dev_array);return -1 ; }
Signature · 1 line
2.24.0
Phil Sutter
reviewerPATCH 3/4 flowtable: Correctly check realloc() call
In reply to Phil SutterIf realloc() fails, it returns NULL but the original pointer is untouchted and therefore still has to be freed. Unconditionally overwriting the old pointer is therefore a bad idea, use a temporary variable instead.
--- src/flowtable.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
src/flowtable.c +5 -6
@@ -388,7 +388,7 @@ static int nftnl_flowtable_parse_hook_cb(const struct nlattr *attr, void *data)static int nftnl_flowtable_parse_devs (struct nlattr *nest,struct nftnl_flowtable *c) { -const char **dev_array; +const char **dev_array, **tmp;int len =0 , size =8 ;struct nlattr *attr;
@@ -401,14 +401,13 @@ static int nftnl_flowtable_parse_devs(struct nlattr *nest, goto err; dev_array[len++] =strdup (mnl_attr_get_str (attr));if (len >= size) { - dev_array =realloc (dev_array, - size *2 *sizeof (char *)); -if (!dev_array) + tmp =realloc (dev_array, size *2 *sizeof (char *)); +if (!tmp) goto err; size *=2 ; -memset (&dev_array[len],0 , - (size - len) *sizeof (char *)); +memset (&tmp[len],0 , (size - len) *sizeof (char *)); + dev_array = tmp; } }
Signature · 1 line
2.24.0
Phil Sutter
reviewerPATCH 4/4 chain: Correctly check realloc() call
In reply to Phil SutterIf realloc() fails, it returns NULL but the original pointer is untouchted and therefore still has to be freed. Unconditionally overwriting the old pointer is therefore a bad idea, use a temporary variable instead.
--- src/chain.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
src/chain.c +5 -6
@@ -605,7 +605,7 @@ static int nftnl_chain_parse_hook_cb(const struct nlattr *attr, void *data)static int nftnl_chain_parse_devs (struct nlattr *nest,struct nftnl_chain *c) { -const char **dev_array; +const char **dev_array, **tmp;int len =0 , size =8 ;struct nlattr *attr;
@@ -618,14 +618,13 @@ static int nftnl_chain_parse_devs(struct nlattr *nest, struct nftnl_chain *c) goto err; dev_array[len++] =strdup (mnl_attr_get_str (attr));if (len >= size) { - dev_array =realloc (dev_array, - size *2 *sizeof (char *)); -if (!dev_array) + tmp =realloc (dev_array, size *2 *sizeof (char *)); +if (!tmp) goto err; size *=2 ; -memset (&dev_array[len],0 , - (size - len) *sizeof (char *)); +memset (&tmp[len],0 , (size - len) *sizeof (char *)); + dev_array = tmp; } }
Signature · 1 line
2.24.0
Quoted 2 lines · Phil Sutter
These are merely memleaks in error paths related to multi device support in flowtables and netdev family chains.
Thanks for fixing up these, Phil.