qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks
@ 2013-01-16 17:15 Markus Armbruster
  2013-01-16 17:15 ` [Qemu-devel] [PATCH 1/2] qemu-ga: Plug memory leak in guest_fsfreeze_cleanup() Markus Armbruster
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Markus Armbruster @ 2013-01-16 17:15 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, lcapitulino

Markus Armbruster (2):
  qemu-ga: Plug memory leak in guest_fsfreeze_cleanup()
  qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths

 qga/commands-posix.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 1/2] qemu-ga: Plug memory leak in guest_fsfreeze_cleanup()
  2013-01-16 17:15 [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks Markus Armbruster
@ 2013-01-16 17:15 ` Markus Armbruster
  2013-01-16 17:15 ` [Qemu-devel] [PATCH 2/2] qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths Markus Armbruster
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Markus Armbruster @ 2013-01-16 17:15 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, lcapitulino

Neglects to free errors allocated by qmp_guest_fsfreeze_thaw().
Spotted by Coverity.

While there, drop the test whether return value is negative (it's
never true), and improve logging.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qga/commands-posix.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 77f6ee7..f95ebc8 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -611,13 +611,14 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)
 
 static void guest_fsfreeze_cleanup(void)
 {
-    int64_t ret;
     Error *err = NULL;
 
     if (ga_is_frozen(ga_state) == GUEST_FSFREEZE_STATUS_FROZEN) {
-        ret = qmp_guest_fsfreeze_thaw(&err);
-        if (ret < 0 || err) {
-            slog("failed to clean up frozen filesystems");
+        qmp_guest_fsfreeze_thaw(&err);
+        if (err) {
+            slog("failed to clean up frozen filesystems: %s",
+                 error_get_pretty(err));
+            error_free(err);
         }
     }
 }
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 2/2] qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths
  2013-01-16 17:15 [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks Markus Armbruster
  2013-01-16 17:15 ` [Qemu-devel] [PATCH 1/2] qemu-ga: Plug memory leak in guest_fsfreeze_cleanup() Markus Armbruster
@ 2013-01-16 17:15 ` Markus Armbruster
  2013-01-16 18:46   ` Luiz Capitulino
  2013-01-16 18:08 ` [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks Eric Blake
  2013-01-16 18:46 ` Luiz Capitulino
  3 siblings, 1 reply; 6+ messages in thread
From: Markus Armbruster @ 2013-01-16 17:15 UTC (permalink / raw)
  To: qemu-devel; +Cc: mdroth, lcapitulino

Spotted by Coverity.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 qga/commands-posix.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index f95ebc8..d6902a9 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -935,9 +935,11 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
                 error_setg_errno(errp, errno,
                                  "failed to get MAC address of %s",
                                  ifa->ifa_name);
+                close(sock);
                 goto error;
             }
 
+            close(sock);
             mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
 
             if (asprintf(&info->value->hardware_address,
@@ -950,20 +952,19 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
             }
 
             info->value->has_hardware_address = true;
-            close(sock);
         }
 
         if (ifa->ifa_addr &&
             ifa->ifa_addr->sa_family == AF_INET) {
             /* interface with IPv4 address */
-            address_item = g_malloc0(sizeof(*address_item));
-            address_item->value = g_malloc0(sizeof(*address_item->value));
             p = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
             if (!inet_ntop(AF_INET, p, addr4, sizeof(addr4))) {
                 error_setg_errno(errp, errno, "inet_ntop failed");
                 goto error;
             }
 
+            address_item = g_malloc0(sizeof(*address_item));
+            address_item->value = g_malloc0(sizeof(*address_item->value));
             address_item->value->ip_address = g_strdup(addr4);
             address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV4;
 
@@ -976,14 +977,14 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
         } else if (ifa->ifa_addr &&
                    ifa->ifa_addr->sa_family == AF_INET6) {
             /* interface with IPv6 address */
-            address_item = g_malloc0(sizeof(*address_item));
-            address_item->value = g_malloc0(sizeof(*address_item->value));
             p = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
             if (!inet_ntop(AF_INET6, p, addr6, sizeof(addr6))) {
                 error_setg_errno(errp, errno, "inet_ntop failed");
                 goto error;
             }
 
+            address_item = g_malloc0(sizeof(*address_item));
+            address_item->value = g_malloc0(sizeof(*address_item->value));
             address_item->value->ip_address = g_strdup(addr6);
             address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV6;
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks
  2013-01-16 17:15 [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks Markus Armbruster
  2013-01-16 17:15 ` [Qemu-devel] [PATCH 1/2] qemu-ga: Plug memory leak in guest_fsfreeze_cleanup() Markus Armbruster
  2013-01-16 17:15 ` [Qemu-devel] [PATCH 2/2] qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths Markus Armbruster
@ 2013-01-16 18:08 ` Eric Blake
  2013-01-16 18:46 ` Luiz Capitulino
  3 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2013-01-16 18:08 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: lcapitulino, qemu-devel, mdroth

[-- Attachment #1: Type: text/plain, Size: 484 bytes --]

On 01/16/2013 10:15 AM, Markus Armbruster wrote:
> Markus Armbruster (2):
>   qemu-ga: Plug memory leak in guest_fsfreeze_cleanup()
>   qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths
> 
>  qga/commands-posix.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)

Series: Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths
  2013-01-16 17:15 ` [Qemu-devel] [PATCH 2/2] qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths Markus Armbruster
@ 2013-01-16 18:46   ` Luiz Capitulino
  0 siblings, 0 replies; 6+ messages in thread
From: Luiz Capitulino @ 2013-01-16 18:46 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, mdroth

On Wed, 16 Jan 2013 18:15:09 +0100
Markus Armbruster <armbru@redhat.com> wrote:

> Spotted by Coverity.

I'd split that patch, but you don't have to respin just because of that.

> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  qga/commands-posix.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index f95ebc8..d6902a9 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -935,9 +935,11 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
>                  error_setg_errno(errp, errno,
>                                   "failed to get MAC address of %s",
>                                   ifa->ifa_name);
> +                close(sock);
>                  goto error;
>              }
>  
> +            close(sock);
>              mac_addr = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
>  
>              if (asprintf(&info->value->hardware_address,
> @@ -950,20 +952,19 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
>              }
>  
>              info->value->has_hardware_address = true;
> -            close(sock);
>          }
>  
>          if (ifa->ifa_addr &&
>              ifa->ifa_addr->sa_family == AF_INET) {
>              /* interface with IPv4 address */
> -            address_item = g_malloc0(sizeof(*address_item));
> -            address_item->value = g_malloc0(sizeof(*address_item->value));
>              p = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr;
>              if (!inet_ntop(AF_INET, p, addr4, sizeof(addr4))) {
>                  error_setg_errno(errp, errno, "inet_ntop failed");
>                  goto error;
>              }
>  
> +            address_item = g_malloc0(sizeof(*address_item));
> +            address_item->value = g_malloc0(sizeof(*address_item->value));
>              address_item->value->ip_address = g_strdup(addr4);
>              address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV4;
>  
> @@ -976,14 +977,14 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
>          } else if (ifa->ifa_addr &&
>                     ifa->ifa_addr->sa_family == AF_INET6) {
>              /* interface with IPv6 address */
> -            address_item = g_malloc0(sizeof(*address_item));
> -            address_item->value = g_malloc0(sizeof(*address_item->value));
>              p = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
>              if (!inet_ntop(AF_INET6, p, addr6, sizeof(addr6))) {
>                  error_setg_errno(errp, errno, "inet_ntop failed");
>                  goto error;
>              }
>  
> +            address_item = g_malloc0(sizeof(*address_item));
> +            address_item->value = g_malloc0(sizeof(*address_item->value));
>              address_item->value->ip_address = g_strdup(addr6);
>              address_item->value->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV6;
>  

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks
  2013-01-16 17:15 [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks Markus Armbruster
                   ` (2 preceding siblings ...)
  2013-01-16 18:08 ` [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks Eric Blake
@ 2013-01-16 18:46 ` Luiz Capitulino
  3 siblings, 0 replies; 6+ messages in thread
From: Luiz Capitulino @ 2013-01-16 18:46 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: qemu-devel, mdroth

On Wed, 16 Jan 2013 18:15:07 +0100
Markus Armbruster <armbru@redhat.com> wrote:

> Markus Armbruster (2):
>   qemu-ga: Plug memory leak in guest_fsfreeze_cleanup()
>   qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths

Nice ones. Series:

Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>

> 
>  qga/commands-posix.c | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-01-16 18:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-16 17:15 [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks Markus Armbruster
2013-01-16 17:15 ` [Qemu-devel] [PATCH 1/2] qemu-ga: Plug memory leak in guest_fsfreeze_cleanup() Markus Armbruster
2013-01-16 17:15 ` [Qemu-devel] [PATCH 2/2] qemu-ga: Plug leaks on qmp_guest_network_get_interfaces() error paths Markus Armbruster
2013-01-16 18:46   ` Luiz Capitulino
2013-01-16 18:08 ` [Qemu-devel] [PATCH 0/2] qemu-ga: Plug a few leaks Eric Blake
2013-01-16 18:46 ` Luiz Capitulino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).