[lxc-devel] [PATCH] Fix clearing IPv4/IPv6 addresses
Serge Hallyn
serge.hallyn at ubuntu.com
Wed Jan 28 11:17:18 UTC 2015
Quoting Stéphane Graber (stgraber at ubuntu.com):
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
Looks good, except that in both functions in the case where
the value is being cleared you may leak the previously allocated
gw.
> ---
> src/lxc/confile.c | 35 ++++++++++++++---------------------
> 1 file changed, 14 insertions(+), 21 deletions(-)
>
> diff --git a/src/lxc/confile.c b/src/lxc/confile.c
> index be81f5d..e9cc474 100644
> --- a/src/lxc/confile.c
> +++ b/src/lxc/confile.c
> @@ -787,29 +787,25 @@ static int config_network_ipv4_gateway(const char *key, const char *value,
> struct lxc_conf *lxc_conf)
> {
> struct lxc_netdev *netdev;
> - struct in_addr *gw;
>
> netdev = network_netdev(key, value, &lxc_conf->network);
> if (!netdev)
> return -1;
>
> - gw = malloc(sizeof(*gw));
> - if (!gw) {
> - SYSERROR("failed to allocate ipv4 gateway address");
> - return -1;
> - }
> -
> - if (!value) {
> - ERROR("no ipv4 gateway address specified");
> - free(gw);
> - return -1;
> - }
> -
> - if (!strcmp(value, "auto")) {
> - free(gw);
> + if (!value || strlen(value) == 0) {
> + netdev->ipv4_gateway = NULL;
> + } else if (!strcmp(value, "auto")) {
> netdev->ipv4_gateway = NULL;
> netdev->ipv4_gateway_auto = true;
> } else {
> + struct in_addr *gw;
> +
> + gw = malloc(sizeof(*gw));
> + if (!gw) {
> + SYSERROR("failed to allocate ipv4 gateway address");
> + return -1;
> + }
> +
> if (!inet_pton(AF_INET, value, gw)) {
> SYSERROR("invalid ipv4 gateway address: %s", value);
> free(gw);
> @@ -892,12 +888,9 @@ static int config_network_ipv6_gateway(const char *key, const char *value,
> if (!netdev)
> return -1;
>
> - if (!value) {
> - ERROR("no ipv6 gateway address specified");
> - return -1;
> - }
> -
> - if (!strcmp(value, "auto")) {
> + if (!value || strlen(value) == 0) {
> + netdev->ipv4_gateway = NULL;
> + } else if (!strcmp(value, "auto")) {
> netdev->ipv6_gateway = NULL;
> netdev->ipv6_gateway_auto = true;
> } else {
> --
> 1.9.1
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
More information about the lxc-devel
mailing list