removed memory leaking when out of memory.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7733 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2004-06-01 20:58:57 +00:00
parent 5256712211
commit 9591761134
2 changed files with 18 additions and 4 deletions

View File

@ -123,8 +123,10 @@ init_driver(void)
if (!item)
return B_NO_MEMORY;
if (get_module(B_PCI_MODULE_NAME, (module_info **)&gPci) < B_OK)
if (get_module(B_PCI_MODULE_NAME, (module_info **)&gPci) < B_OK) {
free(item);
return B_ERROR;
}
for (cards = 0, index = 0; gPci->get_nth_pci_info(index++, item) == B_OK; ) {
const char *info = identify_device(item);
@ -138,7 +140,7 @@ init_driver(void)
cards++;
item = (pci_info *)malloc(sizeof(pci_info));
if (!item)
return B_OK; // already found 1 card, but out of memory
goto err_outofmem;
if (cards == MAX_CARDS)
break;
}
@ -167,6 +169,11 @@ err_mempool:
terminate_timer();
err_timer:
err_cards:
err_outofmem:
for (index = 0; index < cards; index++) {
free(gDevList[index]);
free(gDevNameList[index]);
}
put_module(B_PCI_MODULE_NAME);
return B_ERROR;
}

View File

@ -81,8 +81,10 @@ init_driver(void)
if (!item)
return B_NO_MEMORY;
if (get_module(B_PCI_MODULE_NAME, (module_info **)&gPci) < B_OK)
if (get_module(B_PCI_MODULE_NAME, (module_info **)&gPci) < B_OK) {
free(item);
return B_ERROR;
}
for (cards = 0, index = 0; gPci->get_nth_pci_info(index++, item) == B_OK; ) {
if (item->vendor_id == 0x10ec && item->device_id == 0x8169) {
@ -94,7 +96,7 @@ init_driver(void)
cards++;
item = (pci_info *)malloc(sizeof(pci_info));
if (!item)
return B_OK; // already found 1 card, but out of memory
goto err_outofmem;
if (cards == MAX_CARDS)
break;
}
@ -116,6 +118,11 @@ init_driver(void)
err_timer:
err_cards:
err_outofmem:
for (index = 0; index < cards; index++) {
free(gDevList[index]);
free(gDevNameList[index]);
}
put_module(B_PCI_MODULE_NAME);
return B_ERROR;
}