Changeset 677


Ignore:
Timestamp:
05/29/05 16:30:32 (7 years ago)
Author:
aj
Message:

add/fix/unify out of memory handling.

Location:
trunk/src/ifd
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ifd/conf.c

    r656 r677  
    201201 
    202202        node = (ifd_conf_node_t *) calloc(1, sizeof(*node)); 
     203        if (!node) { 
     204                ct_error("out of memory"); 
     205                return NULL; 
     206        } 
    203207        node->name = strdup(name); 
    204208 
  • trunk/src/ifd/device.c

    r657 r677  
    4646 
    4747        dev = (ifd_device_t *) calloc(1, size); 
     48        if (!dev) { 
     49                ct_error("out of memory"); 
     50                return NULL; 
     51        } 
    4852        dev->name = strdup(name); 
    4953        dev->ops = ops; 
  • trunk/src/ifd/driver.c

    r657 r677  
    3636 
    3737        ip = (struct ifd_driver_info *)calloc(1, sizeof(*ip)); 
     38        if (!ip) { 
     39                ct_error("out of memory"); 
     40                return NULL; 
     41        } 
    3842        ip->driver.name = strdup(name); 
    3943        ip->next = list; 
     
    5559} 
    5660 
    57 void ifd_driver_add_id(const char *id, const char *name) 
     61int ifd_driver_add_id(const char *id, const char *name) 
    5862{ 
    5963        struct ifd_driver_info *ip; 
     
    6165        ifd_debug(3, "ifd_driver_add_id(%s, %s)", id, name); 
    6266        ip = find_by_name(name, 1); 
     67        if (!ip) 
     68                return -1; 
     69 
    6370        ip->id = (ifd_devid_t *) realloc(ip->id, 
    6471                                         (ip->nids + 1) * sizeof(ifd_devid_t)); 
     72        if (!ip->id) { 
     73                ct_error("out of memory"); 
     74                return IFD_ERROR_NO_MEMORY; 
     75        } 
    6576        if (ifd_device_id_parse(id, &ip->id[ip->nids]) >= 0) 
    6677                ip->nids++; 
  • trunk/src/ifd/ifd-cardman.c

    r658 r677  
    5959        } 
    6060        priv = (cm_priv_t *) calloc(1, sizeof(cm_priv_t)); 
     61        if (!priv) { 
     62                ct_error("out of memory"); 
     63                return IFD_ERROR_NO_MEMORY; 
     64        } 
    6165 
    6266        reader->driver_data = priv; 
  • trunk/src/ifd/ifd-ccid.c

    r622 r677  
    559559     } 
    560560 
    561      if ((st = (ccid_status_t *) calloc(1, sizeof(*st))) == NULL) 
     561     if ((st = (ccid_status_t *) calloc(1, sizeof(*st))) == NULL) { 
     562          ct_error("out of memory"); 
    562563          return IFD_ERROR_NO_MEMORY; 
     564     } 
    563565 
    564566     st->usb_interface=intf->bInterfaceNumber; 
     
    978980     } 
    979981 
    980      apdu=(unsigned char *) malloc(len); 
    981      if (!apdu) 
     982     apdu=(unsigned char *) calloc(1,len); 
     983     if (!apdu) { 
     984          ct_error("out of memory"); 
    982985          return IFD_ERROR_NO_MEMORY; 
     986     } 
    983987     memcpy(apdu, buffer, len); 
    984988     st->sbuf[dad]=apdu; 
  • trunk/src/ifd/ifd-cm4000.c

    r671 r677  
    4646 
    4747        priv = (cm_priv_t *) calloc(1, sizeof(cm_priv_t)); 
     48        if (!priv) { 
     49                ct_error("out of memory"); 
     50                return IFD_ERROR_NO_MEMORY; 
     51        } 
    4852 
    4953        reader->driver_data = priv; 
  • trunk/src/ifd/ifd-gempc.c

    r667 r677  
    7272 
    7373        st = (gpc_status_t *) calloc(1, sizeof(*st)); 
     74        if (!st) { 
     75                ct_error("out of memory"); 
     76                return IFD_ERROR_NO_MEMORY; 
     77        } 
    7478        reader->driver_data = st; 
    7579 
  • trunk/src/ifd/ifd-kaan.c

    r667 r677  
    8787 
    8888        reader->device = dev; 
    89         if ((st = (kaan_status_t *) calloc(1, sizeof(*st))) == NULL) 
     89        if ((st = (kaan_status_t *) calloc(1, sizeof(*st))) == NULL) { 
     90                ct_error("out of memory"); 
    9091                return IFD_ERROR_NO_MEMORY; 
     92        } 
    9193        st->reader_type = TYPE_KAAN; 
    9294        st->icc_proto[0] = -1; 
     
    170172 
    171173        reader->device = dev; 
    172         if ((st = (kaan_status_t *) calloc(1, sizeof(*st))) == NULL) 
     174        if ((st = (kaan_status_t *) calloc(1, sizeof(*st))) == NULL) { 
     175                ct_error("out of memory"); 
    173176                return IFD_ERROR_NO_MEMORY; 
     177        } 
    174178        st->reader_type = TYPE_B1; 
    175179        st->icc_proto[0] = -1; 
  • trunk/src/ifd/locks.c

    r664 r677  
    4343        /* No conflict - grant lock and record this fact */ 
    4444        l = (ct_lock_t *) calloc(1, sizeof(*l)); 
     45        if (!l) { 
     46                ct_error("out of memory"); 
     47                return IFD_ERROR_NO_MEMORY; 
     48        } 
    4549        l->exclusive = (type == IFD_LOCK_EXCLUSIVE); 
    4650        l->uid = sock->client_uid; 
  • trunk/src/ifd/protocol.c

    r663 r677  
    1919 * Register a protocol 
    2020 */ 
    21 void ifd_protocol_register(struct ifd_protocol_ops *ops) 
     21int ifd_protocol_register(struct ifd_protocol_ops *ops) 
    2222{ 
    2323        struct ifd_protocol_info *info, **ptr; 
    2424 
    2525        info = (struct ifd_protocol_info *)calloc(1, sizeof(*info)); 
     26        if (!info) { 
     27                ct_error("out of memory"); 
     28                return IFD_ERROR_NO_MEMORY; 
     29        } 
    2630        info->ops = ops; 
    2731 
    2832        for (ptr = &list; *ptr; ptr = &(*ptr)->next) ; 
    2933        *ptr = info; 
     34        return 0; 
    3035} 
    3136 
     
    199204 
    200205        p = (ifd_protocol_t *) calloc(1, ops->size); 
     206        if (!p) { 
     207                ct_error("out of memory"); 
     208                return p; 
     209        } 
    201210        p->reader = reader; 
    202211        p->ops = ops; 
  • trunk/src/ifd/ria-server.c

    r662 r677  
    260260 
    261261        clnt = (ria_peer_t *) calloc(1, sizeof(ria_peer_t)); 
     262        if (!clnt) { 
     263                ct_error("out of memory"); 
     264                return NULL; 
     265        } 
    262266        clnt->sock = sock; 
    263267        ria_svc_link(clnt); 
  • trunk/src/ifd/ria.c

    r662 r677  
    3838 
    3939        clnt = (ria_client_t *) calloc(1, sizeof(*clnt) + RIA_QUEUE_LEN); 
     40        if (!clnt) { 
     41                ct_error("out of memory"); 
     42                return NULL; 
     43        } 
    4044        ct_buf_init(&clnt->data, (clnt + 1), RIA_QUEUE_LEN); 
    4145 
  • trunk/src/ifd/sys-bsd.c

    r661 r677  
    160160 
    161161        if (!(cap = (ifd_usb_capture_t *) calloc(1, sizeof(*cap) + maxpacket))) { 
    162                 ct_debug("ifd_sysdep_usb_begin_capture: calloc failed"); 
    163                 return -1; 
     162                ct_error("out of memory"); 
     163                return IFD_ERROR_NO_MEMORY; 
    164164        } 
    165165        cap->type = type; 
  • trunk/src/ifd/sys-linux.c

    r661 r677  
    199199 
    200200        cap = (ifd_usb_capture_t *) calloc(1, sizeof(*cap) + maxpacket); 
     201        if (!cap) { 
     202                ct_error("out of memory"); 
     203                return IFD_ERROR_NO_MEMORY; 
     204        } 
    201205 
    202206        cap->type = type; 
  • trunk/src/ifd/sys-solaris.c

    r661 r677  
    8585                char *devstat; 
    8686 
    87                 if ((devstat = malloc(strlen(name) + 2)) == NULL) { 
    88                         ct_error("devstat malloc failed"); 
    89                         return -1; 
    90                 } 
    91                 memset(devstat, 0, strlen(name) + 2); 
     87                if ((devstat = calloc(1,strlen(name) + 2)) == NULL) { 
     88                        ct_error("out of memory"); 
     89                        return IFD_ERROR_NO_MEMORY; 
     90                } 
    9291                strcpy(devstat, name); 
    9392                strcpy(devstat + strlen(name) - 6, "devstat"); 
     
    118117                char *cntrl0stat; 
    119118 
    120                 if ((cntrl0stat = malloc(strlen(name) + 5)) == NULL) { 
    121                         ct_error("cntrl0stat malloc failed"); 
     119                if ((cntrl0stat = calloc(1, strlen(name) + 5)) == NULL) { 
     120                        ct_error("out of memory"); 
    122121                        return -1; 
    123122                } 
    124                 memset(cntrl0stat, 0, strlen(name) + 5); 
    125123                strcpy(cntrl0stat, name); 
    126124                strcat(cntrl0stat, "stat"); 
     
    306304        bytes_to_process = USB_REQUEST_SIZE + 
    307305            ((requesttype & USB_EP_DIR_MASK) == USB_EP_DIR_OUT ? len : 0); 
    308         if ((usb_control_req = malloc(bytes_to_process)) == NULL) { 
    309                 ct_error("usb_control_req malloc failed"); 
    310                 return -1; 
    311         } 
    312         memset(usb_control_req, 0, bytes_to_process); 
    313         if ((recv_data = malloc(len)) == NULL) { 
    314                 ct_error("recv_data malloc failed"); 
     306        if ((usb_control_req = calloc(1,bytes_to_process)) == NULL) { 
     307                ct_error("out of memory"); 
     308                return -1; 
     309        } 
     310        if ((recv_data = calloc(1,len)) == NULL) { 
     311                ct_error("out of memory"); 
    315312                free(usb_control_req); 
    316313                return -1; 
     
    464461 
    465462        if (!(cap = (ifd_usb_capture_t *) calloc(1, sizeof(*cap) + maxpacket))) { 
    466                 ct_debug("ifd_sysdep_usb_begin_capture: cannot calloc"); 
     463                ct_error("out of memory"); 
    467464                return -1; 
    468465        } 
  • trunk/src/ifd/sys-sunray.c

    r661 r677  
    115115 
    116116        if (!(cap = (ifd_usb_capture_t *) calloc(1, sizeof(*cap) + maxpacket))) { 
    117                 ct_debug("ifd_sysdep_usb_begin_capture: calloc failed"); 
    118                 return -1; 
     117                ct_error("out of memory"); 
     118                return IFD_ERROR_NO_MEMORY; 
    119119        } 
    120120        cap->type = type; 
  • trunk/src/ifd/usb-descriptors.c

    r660 r677  
    9292        endpoint->extra = (unsigned char *)malloc(len); 
    9393        if (!endpoint->extra) { 
    94                 ct_debug 
    95                     ("couldn't allocate memory for endpoint extra descriptors"); 
     94                ct_error("out of memory"); 
    9695                endpoint->extralen = 0; 
    9796                return parsed; 
     
    121120                        ); 
    122121                if (!interface->altsetting) { 
    123                         ct_debug("couldn't malloc interface->altsetting"); 
     122                        ct_error("out of memory"); 
    124123                        return -1; 
    125124                } 
     
    176175                        ifp->extra = (unsigned char *)malloc(len); 
    177176                        if (!ifp->extra) { 
    178                                 ct_debug 
    179                                     ("couldn't allocate memory for interface extra descriptors"); 
     177                                ct_error("out of memory"); 
    180178                                ifp->extralen = 0; 
    181179                                return -1; 
Note: See TracChangeset for help on using the changeset viewer.