Check the reallocation in usb_hid. Use B_NO_MEMORY instead of B_ERROR in other checks.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18495 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz 2006-08-12 10:14:55 +00:00
parent 4872c00b87
commit 852c3506f5

View File

@ -717,6 +717,7 @@ hid_device_added(const usb_device *dev, void **cookie)
desc_len = hid_desc->descriptor_info[0].descriptor_length; desc_len = hid_desc->descriptor_info[0].descriptor_length;
free(hid_desc); free(hid_desc);
rep_desc = malloc(desc_len); rep_desc = malloc(desc_len);
if (rep_desc == NULL) if (rep_desc == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@ -770,9 +771,9 @@ hid_device_added(const usb_device *dev, void **cookie)
num_items = desc_len; /* XXX */ num_items = desc_len; /* XXX */
items = malloc(sizeof (decomp_item) * num_items); items = malloc(sizeof (decomp_item) * num_items);
if (items == NULL) { if (items == NULL) {
// TODO: free device remove_device(device);
free(rep_desc); free(rep_desc);
return B_ERROR; return B_NO_MEMORY;
} }
decompose_report_descriptor(rep_desc, desc_len, items, &num_items); decompose_report_descriptor(rep_desc, desc_len, items, &num_items);
@ -782,12 +783,23 @@ hid_device_added(const usb_device *dev, void **cookie)
device->num_insns = num_items; /* XXX */ device->num_insns = num_items; /* XXX */
device->insns = malloc (sizeof (report_insn) * device->num_insns); device->insns = malloc (sizeof (report_insn) * device->num_insns);
assert (device->insns != NULL); if (device->insns == NULL) {
remove_device(device);
free(items);
return B_NO_MEMORY;
}
parse_report_descriptor (items, num_items, device->insns, parse_report_descriptor (items, num_items, device->insns,
&device->num_insns, &device->total_report_size, &report_id); &device->num_insns, &device->total_report_size, &report_id);
free(items); free(items);
device->insns = realloc(device->insns, sizeof (report_insn) device->insns = realloc(device->insns, sizeof (report_insn)
* device->num_insns); * device->num_insns);
if (device->insns == NULL) {
remove_device(device);
return B_NO_MEMORY;
}
DPRINTF_INFO ((MY_ID "%d items, %d insns, %d bytes\n", DPRINTF_INFO ((MY_ID "%d items, %d insns, %d bytes\n",
(int)num_items, (int)device->num_insns, (int)device->total_report_size)); (int)num_items, (int)device->num_insns, (int)device->total_report_size));