Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc3b459f authored by Elliott Hughes's avatar Elliott Hughes
Browse files

Add missing null checks after allocations.

Bug: http://b/20317729
Change-Id: I62bb761d48ee59a1f4ddd0cdd0632432305ca2ca
parent 9a0cea92
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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;

+4 −0
Original line number Diff line number Diff line
@@ -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);
+9 −8
Original line number Diff line number Diff line
@@ -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));
+2 −2
Original line number Diff line number Diff line
@@ -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;
+4 −0
Original line number Diff line number Diff line
@@ -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;
Loading