[libvirt] [PATCH] Fix leak on OOM when creating nwfilter rule instances

Stefan Berger stefanb at linux.vnet.ibm.com
Wed Mar 19 16:35:25 UTC 2014


On 03/17/2014 07:59 AM, Daniel P. Berrange wrote:
> The ebiptablesAddRuleInst method would leak an instance
> of ebiptablesRuleInstPtr if it hit OOM when adding it
> to the list of instances. Remove the pointless helper
> method virNWFilterRuleInstAddData and just inline the
> call to VIR_APPEND_ELEMENT and free the instance on
> failure.
>
> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> ---
>   src/nwfilter/nwfilter_ebiptables_driver.c |  6 +++++-
>   src/nwfilter/nwfilter_gentech_driver.c    | 22 ----------------------
>   src/nwfilter/nwfilter_gentech_driver.h    |  3 ---
>   3 files changed, 5 insertions(+), 26 deletions(-)
>
> diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
> index 9dbd3ff..e1e0af8 100644
> --- a/src/nwfilter/nwfilter_ebiptables_driver.c
> +++ b/src/nwfilter/nwfilter_ebiptables_driver.c
> @@ -505,7 +505,11 @@ ebiptablesAddRuleInst(virNWFilterRuleInstPtr res,
>       inst->priority = priority;
>       inst->ruleType = ruleType;
>
> -    return virNWFilterRuleInstAddData(res, inst);
> +    if (VIR_APPEND_ELEMENT(res->data, res->ndata, inst) < 0) {
> +        VIR_FREE(inst);
> +        return -1;
> +    }
> +    return 0;
>   }
ACK




More information about the libvir-list mailing list