am 876881b2: Merge "Add missing null checks after allocations."
* commit '876881b22ad5d735cdb3ae2ac1afa6c336378808': Add missing null checks after allocations.
This commit is contained in:
commit
d1eec0de6a
|
@ -312,6 +312,7 @@ static void read_status_line(int fd, char* buf, size_t count)
|
|||
static void copy_to_file(int inFd, int outFd) {
|
||||
const size_t BUFSIZE = 32 * 1024;
|
||||
char* buf = (char*) malloc(BUFSIZE);
|
||||
if (buf == nullptr) fatal("couldn't allocate buffer for copy_to_file");
|
||||
int len;
|
||||
long total = 0;
|
||||
|
||||
|
@ -419,6 +420,11 @@ static int interactive_shell() {
|
|||
fdi = 0; //dup(0);
|
||||
|
||||
int* fds = reinterpret_cast<int*>(malloc(sizeof(int) * 2));
|
||||
if (fds == nullptr) {
|
||||
fprintf(stderr, "couldn't allocate fds array: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
fds[0] = fd;
|
||||
fds[1] = fdi;
|
||||
|
||||
|
|
|
@ -689,6 +689,10 @@ asocket* host_service_to_socket(const char* name, const char *serial)
|
|||
return create_device_tracker();
|
||||
} else if (!strncmp(name, "wait-for-", strlen("wait-for-"))) {
|
||||
auto sinfo = reinterpret_cast<state_info*>(malloc(sizeof(state_info)));
|
||||
if (sinfo == nullptr) {
|
||||
fprintf(stderr, "couldn't allocate state_info: %s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (serial)
|
||||
sinfo->serial = strdup(serial);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -598,8 +598,8 @@ static void register_device(const char *dev_name, const char *devpath,
|
|||
|
||||
D("[ usb located new device %s (%d/%d/%d) ]\n",
|
||||
dev_name, ep_in, ep_out, interface);
|
||||
usb_handle* usb = reinterpret_cast<usb_handle*>(
|
||||
calloc(1, sizeof(usb_handle)));
|
||||
usb_handle* usb = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle)));
|
||||
if (usb == nullptr) fatal("couldn't allocate usb_handle");
|
||||
strcpy(usb->fname, dev_name);
|
||||
usb->ep_in = ep_in;
|
||||
usb->ep_out = ep_out;
|
||||
|
|
|
@ -241,6 +241,8 @@ static void usb_adb_kick(usb_handle *h)
|
|||
static void usb_adb_init()
|
||||
{
|
||||
usb_handle* h = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle)));
|
||||
if (h == nullptr) fatal("couldn't allocate usb_handle");
|
||||
|
||||
h->write = usb_adb_write;
|
||||
h->read = usb_adb_read;
|
||||
h->kick = usb_adb_kick;
|
||||
|
@ -468,6 +470,8 @@ static void usb_ffs_init()
|
|||
D("[ usb_init - using FunctionFS ]\n");
|
||||
|
||||
usb_handle* h = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle)));
|
||||
if (h == nullptr) fatal("couldn't allocate usb_handle");
|
||||
|
||||
h->write = usb_ffs_write;
|
||||
h->read = usb_ffs_read;
|
||||
h->kick = usb_ffs_kick;
|
||||
|
|
|
@ -336,6 +336,7 @@ CheckInterface(IOUSBInterfaceInterface **interface, UInt16 vendor, UInt16 produc
|
|||
goto err_bad_adb_interface;
|
||||
|
||||
handle = reinterpret_cast<usb_handle*>(calloc(1, sizeof(usb_handle)));
|
||||
if (handle == nullptr) goto err_bad_adb_interface;
|
||||
|
||||
//* Iterate over the endpoints for this interface and find the first
|
||||
//* bulk in/out pipes available. These will be our read/write pipes.
|
||||
|
|
Loading…
Reference in New Issue