On 28/10/16 18:42, Heiko Hund wrote:
> Prevent the re-allocations of memory when the internal argv grows
> beyond 2 and 4 arguments by initially allocating argv to hold up to
> 7 (+ trailing NULL) pointers.
> 
> While at it rename argv_reset to argv_free to actually express
> what's going on. Redo the argv_reset functionality so that it can
> be used to actually reset the argv without re-allocation.
> 
> Signed-off-by: Heiko Hund <heiko.h...@sophos.com>
> ---
>  src/openvpn/argv.c                   | 45 
> ++++++++++++++++++++----------------
>  src/openvpn/argv.h                   |  2 +-
>  src/openvpn/console_systemd.c        |  2 +-
>  src/openvpn/init.c                   |  2 +-
>  src/openvpn/lladdr.c                 |  2 +-
>  src/openvpn/misc.c                   |  4 ++--
>  src/openvpn/multi.c                  | 10 ++++----
>  src/openvpn/options.c                |  2 +-
>  src/openvpn/plugin.c                 |  2 +-
>  src/openvpn/route.c                  |  8 +++----
>  src/openvpn/socket.c                 |  4 ++--
>  src/openvpn/ssl_verify.c             |  6 ++---
>  src/openvpn/tun.c                    | 23 ++++++++----------
>  tests/unit_tests/openvpn/test_argv.c | 41 +++++++++++++++++++++-----------
>  14 files changed, 85 insertions(+), 68 deletions(-)
> 

Code looks fairly reasonable, but I have a few comments ...

>  argv_init (struct argv *a)
>  {
>    a->capacity = 0;
>    a->argc = 0;
>    a->argv = NULL;
> +  argv_extend (a, 8);

Why 8?  Done any performance and/or memory utilization tests?  Does the
overall memory consumption increase with this?

>  void
> -argv_reset (struct argv *a)
> +argv_free (struct argv *a)

This makes more sense :)

> @@ -126,10 +138,7 @@ argv_insert_head (const struct argv *a, const char *head)
>  const char *
>  argv_str (const struct argv *a, struct gc_arena *gc, const unsigned int 
> flags)
>  {
> -  if (a->argv)
> -    return print_argv ((const char **)a->argv, gc, flags);
> -  else
> -    return "";
> +  return print_argv ((const char **)a->argv, gc, flags);

There are very few callers of print_argv() (defined in buffer.c).
Should we migrate print_argv() into this function and move all callers
over to argv_str() instead?

> diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
> --- a/src/openvpn/tun.c
> +++ b/src/openvpn/tun.c

tun.c:2360 close_tun() seems to be missing a argv_free(), or?
The same goes for close_tun() in tun.c:2482 and tun.c:2956
(tun.c:2821 does have it though).

Similarly, in open_tun() [tun.c:2926], argv_new() is called but no
argv_free() calls.



On a not so related note.  I noticed that init.c have a
#ifdef ARGV_TEST block.  That should probably also be killed; no need
for that as we have unit tests - and the argv_test() function it calls
no longer exists.


-- 
kind regards,

David Sommerseth
OpenVPN Technologies, Inc


Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
_______________________________________________
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to