From 6971db8cca83e30dd996a3d519fafaff95014ed2 Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Thu, 23 Apr 2009 21:01:57 +0000 Subject: [PATCH] Do not leak the delegate, as suggested by Stippi git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30355 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/bluetooth/LocalDeviceImpl.cpp | 30 +++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/servers/bluetooth/LocalDeviceImpl.cpp b/src/servers/bluetooth/LocalDeviceImpl.cpp index 69aee2bf2a..f7e89961cf 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.cpp +++ b/src/servers/bluetooth/LocalDeviceImpl.cpp @@ -34,24 +34,34 @@ LocalDeviceImpl* LocalDeviceImpl::CreateControllerAccessor(BPath* path) { - HCIDelegate* hd = new (std::nothrow)HCIControllerAccessor(path); - - if (hd != NULL) - return new (std::nothrow)LocalDeviceImpl(hd); - else + HCIDelegate* delegate = new(std::nothrow) HCIControllerAccessor(path); + if (delegate == NULL) return NULL; + + LocalDeviceImpl* device = new(std::nothrow) LocalDeviceImpl(delegate); + if (device == NULL) { + delete delegate; + return NULL; + } + + return device; } LocalDeviceImpl* LocalDeviceImpl::CreateTransportAccessor(BPath* path) { - HCIDelegate* hd = new (std::nothrow)HCITransportAccessor(path); - - if (hd != NULL) - return new (std::nothrow)LocalDeviceImpl(hd); - else + HCIDelegate* delegate = new(std::nothrow) HCITransportAccessor(path); + if (delegate == NULL) return NULL; + + LocalDeviceImpl* device = new(std::nothrow) LocalDeviceImpl(delegate); + if (device == NULL) { + delete delegate; + return NULL; + } + + return device; }