diff options
author | Elliott Hughes <enh@google.com> | 2015-04-21 19:39:52 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-04-21 19:43:22 -0700 |
commit | dc3b459ff9f0ff71d404ba7198083e532a0dd894 (patch) | |
tree | 3e64efa2fefb22f72fbeb303a672353fb219de16 /adb/transport.cpp | |
parent | 9a0cea92c8b74114b70ac3339b2b611633f6a31a (diff) | |
download | system_core-dc3b459ff9f0ff71d404ba7198083e532a0dd894.zip system_core-dc3b459ff9f0ff71d404ba7198083e532a0dd894.tar.gz system_core-dc3b459ff9f0ff71d404ba7198083e532a0dd894.tar.bz2 |
Add missing null checks after allocations.
Bug: http://b/20317729
Change-Id: I62bb761d48ee59a1f4ddd0cdd0632432305ca2ca
Diffstat (limited to 'adb/transport.cpp')
-rw-r--r-- | adb/transport.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/adb/transport.cpp b/adb/transport.cpp index 37f9d7b..d395a80 100644 --- a/adb/transport.cpp +++ b/adb/transport.cpp @@ -493,10 +493,8 @@ device_tracker_ready( asocket* socket ) asocket* create_device_tracker(void) { - device_tracker* tracker = reinterpret_cast<device_tracker*>( - calloc(1, sizeof(*tracker))); - - if(tracker == 0) fatal("cannot allocate device tracker"); + device_tracker* tracker = reinterpret_cast<device_tracker*>(calloc(1, sizeof(*tracker))); + if (tracker == nullptr) fatal("cannot allocate device tracker"); D( "device tracker %p created\n", tracker); @@ -1002,8 +1000,11 @@ void close_usb_devices() int register_socket_transport(int s, const char *serial, int port, int local) { - atransport *t = reinterpret_cast<atransport*>( - calloc(1, sizeof(atransport))); + atransport *t = reinterpret_cast<atransport*>(calloc(1, sizeof(atransport))); + if (t == nullptr) { + return -1; + } + atransport *n; char buff[32]; @@ -1102,8 +1103,8 @@ void unregister_all_tcp_transports() void register_usb_transport(usb_handle *usb, const char *serial, const char *devpath, unsigned writeable) { - atransport *t = reinterpret_cast<atransport*>( - calloc(1, sizeof(atransport))); + atransport *t = reinterpret_cast<atransport*>(calloc(1, sizeof(atransport))); + if (t == nullptr) fatal("cannot allocate USB atransport"); D("transport: %p init'ing for usb_handle %p (sn='%s')\n", t, usb, serial ? serial : ""); init_usb_transport(t, usb, (writeable ? CS_OFFLINE : CS_NOPERM)); |