Skip to contentSkip to conversation

sockets: Plug memory leak in socket_address_flatten()

PATCH In review Markus Armbruster 2 participants 3 messages May 15, 2017 – May 16, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sockets: Plug memory leak in socket_address_flatten()

socket_address_flatten() leaks a SocketAddress when its argument is null. Happens when opening a ChardevBackend of type 'udp' that is configured without a local address. Screwed up in commit bd269ebc due to last minute semantic conflict resolution. Spotted by Coverity.

---
 util/qemu-sockets.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
util/qemu-sockets.c +3 -1
index d8183f7..b39ae74 100644
@@ -1338,12 +1338,14 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
 
 SocketAddress *socket_address_flatten(SocketAddressLegacy *addr_legacy)
 {
-    SocketAddress *addr = g_new(SocketAddress, 1);
+    SocketAddress *addr;
 
     if (!addr_legacy) {
         return NULL;
     }
 
+    addr = g_new(SocketAddress, 1);
+
     switch (addr_legacy->type) {
     case SOCKET_ADDRESS_LEGACY_KIND_INET:
         addr->type = SOCKET_ADDRESS_TYPE_INET;
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Markus Armbruster

socket_address_flatten() leaks a SocketAddress when its argument is null. Happens when opening a ChardevBackend of type 'udp' that is configured without a local address. Screwed up in commit bd269ebc due to last minute semantic conflict resolution. Spotted by Coverity.

---
 util/qemu-sockets.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Matches the fix I had proposed here against the v2 pull request:
https://lists.gnu.org/archive/html/qemu-devel/2017-05/msg01825.html

I guess in the confusion of the rebasing, you didn't quite implement it in v3 the way I had proposed.

Quoted 22 lines
util/qemu-sockets.c +3 -1
index d8183f7..b39ae74 100644
@@ -1338,12 +1338,14 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
 
 SocketAddress *socket_address_flatten(SocketAddressLegacy *addr_legacy)
 {
-    SocketAddress *addr = g_new(SocketAddress, 1);
+    SocketAddress *addr;
 
     if (!addr_legacy) {
         return NULL;
     }
 
+    addr = g_new(SocketAddress, 1);
+
     switch (addr_legacy->type) {
     case SOCKET_ADDRESS_LEGACY_KIND_INET:
         addr->type = SOCKET_ADDRESS_TYPE_INET;
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#2 lore raw
Quoted 11 lines · Eric Blake
Quoted 9 lines · Markus Armbruster

socket_address_flatten() leaks a SocketAddress when its argument is null. Happens when opening a ChardevBackend of type 'udp' that is configured without a local address. Screwed up in commit bd269ebc due to last minute semantic conflict resolution. Spotted by Coverity.

---
 util/qemu-sockets.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 7 lines

Matches the fix I had proposed here against the v2 pull request:
https://lists.gnu.org/archive/html/qemu-devel/2017-05/msg01825.html

I guess in the confusion of the rebasing, you didn't quite implement it in v3 the way I had proposed.

I had started to resolve conflicts myself when the message carrying your solution arrived, and I obviously screwed up merging it into my unclean tree. In other words: it's all my fault.