Re: [PATCH 09/17] Fix leak in qemuParseCommandLineDisk on OOM

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Sep 24, 2013 at 11:03 AM, Daniel P. Berrange
<berrange@xxxxxxxxxx> wrote:
> From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>
>
> If OOM occurs in qemuParseCommandLineDisk some intermediate
> variables will be leaked when parsing Sheepdog or RBD disks.
>
> Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
> ---
>  src/qemu/qemu_command.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index a82c5dd..f6a3aa2 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -9935,8 +9935,10 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
>                      if (VIR_STRDUP(def->src, p + strlen("rbd:")) < 0)
>                          goto error;
>                      /* old-style CEPH_ARGS env variable is parsed later */
> -                    if (!old_style_ceph_args && qemuParseRBDString(def) < 0)
> -                        goto cleanup;
> +                    if (!old_style_ceph_args && qemuParseRBDString(def) < 0) {
> +                        VIR_FREE(p);
> +                        goto error;
> +                    }
>
>                      VIR_FREE(p);
>                  } else if (STRPREFIX(def->src, "gluster:") ||
> @@ -9960,17 +9962,20 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
>                      def->protocol = VIR_DOMAIN_DISK_PROTOCOL_SHEEPDOG;
>                      if (VIR_STRDUP(def->src, p + strlen("sheepdog:")) < 0)
>                          goto error;
> +                    VIR_FREE(p);
>
>                      /* def->src must be [vdiname] or [host]:[port]:[vdiname] */
>                      port = strchr(def->src, ':');
>                      if (port) {
> -                        *port++ = '\0';
> -                        vdi = strchr(port, ':');
> +                        *port = '\0';
> +                        vdi = strchr(port + 1, ':');
>                          if (!vdi) {
> +                            *port = ':';

Is this bit necessary? Or is it for making the error message look better?

>                              virReportError(VIR_ERR_INTERNAL_ERROR,
> -                                           _("cannot parse sheepdog filename '%s'"), p);
> +                                           _("cannot parse sheepdog filename '%s'"), def->src);
>                              goto error;
>                          }
> +                        port++;
>                          *vdi++ = '\0';
>                          if (VIR_ALLOC(def->hosts) < 0)
>                              goto error;
> @@ -9983,8 +9988,6 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt,
>                          if (VIR_STRDUP(def->src, vdi) < 0)
>                              goto error;
>                      }
> -
> -                    VIR_FREE(p);
>                  } else
>                      def->type = VIR_DOMAIN_DISK_TYPE_FILE;
>              } else {
> --
> 1.8.3.1
>
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

ACK. Just a question above if a line is necessary.

-- 
Doug Goldstein

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]