Changeset 150
- Timestamp:
- 03/01/09 21:17:46 (16 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/regfi.h
r149 r150 224 224 225 225 226 /* Key Value*/226 /* Value record */ 227 227 typedef struct 228 228 { … … 230 230 uint32 cell_size; /* ((start_offset - end_offset) & 0xfffffff8) */ 231 231 232 REGFI_HBIN* hbin; /* pointer to HBIN record (in memory) containing233 * this nk record234 */235 232 uint8* data; 233 char* valuename; 236 234 uint16 name_length; 237 char* valuename;238 235 uint32 hbin_off; /* offset from beginning of this hbin block */ 239 236 … … 420 417 const REGFI_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i); 421 418 const REGFI_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i); 422 const REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i); 423 const REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i); 424 const REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i); 419 420 REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i); 421 REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i); 422 REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i); 425 423 426 424 bool regfi_iterator_find_value(REGFI_ITERATOR* i, 427 425 const char* value_name); 428 const REGFI_VK_REC*regfi_iterator_first_value(REGFI_ITERATOR* i);429 const REGFI_VK_REC*regfi_iterator_cur_value(REGFI_ITERATOR* i);430 const REGFI_VK_REC*regfi_iterator_next_value(REGFI_ITERATOR* i);426 REGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i); 427 REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i); 428 REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i); 431 429 432 430 … … 471 469 * A newly allocated NK record structure, or NULL on failure. 472 470 */ 473 REGFI_NK_REC* regfi_parse_nk(REGFI_FILE* file, uint32 offset, 471 REGFI_NK_REC* regfi_parse_nk(REGFI_FILE* file, uint32 offset, 474 472 uint32 max_size, bool strict); 475 473 … … 498 496 uint32 max_size, bool strict); 499 497 498 /* Dispose of previously parsed records */ 499 void regfi_free_key(REGFI_NK_REC* nk); 500 void regfi_free_value(REGFI_VK_REC* vk); 501 502 500 503 501 504 /************************************/ … … 503 506 /************************************/ 504 507 REGFI_NK_REC* regfi_rootkey(REGFI_FILE* file); 505 void regfi_key_free(REGFI_NK_REC* nk);506 508 void regfi_subkeylist_free(REGFI_SUBKEY_LIST* list); 507 509 uint32 regfi_read(int fd, uint8* buf, uint32* length); -
trunk/include/void_stack.h
r111 r150 1 1 /* 2 * Copyright (C) 2005,2007 Timothy D. Morgan2 * Copyright (C) 2005,2007,2009 Timothy D. Morgan 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify … … 18 18 */ 19 19 20 #ifndef _VOID_STACK_H 21 #define _VOID_STACK_H 22 20 23 #include <stdlib.h> 21 24 #include <stdbool.h> 22 25 #include <string.h> 23 24 #ifndef _VOID_STACK_H 25 #define _VOID_STACK_H 26 #include "talloc.h" 26 27 27 28 typedef struct _void_stack -
trunk/lib/range_list.c
r148 r150 143 143 void range_list_free(range_list* rl) 144 144 { 145 if(rl == NULL) 146 return; 147 148 talloc_free(rl); 145 if(rl != NULL) 146 talloc_free(rl); 149 147 } 150 148 -
trunk/lib/regfi.c
r148 r150 560 560 { 561 561 num_sublists = ret_val->num_children; 562 sublists = (REGFI_SUBKEY_LIST**) zalloc(num_sublists562 sublists = (REGFI_SUBKEY_LIST**)malloc(num_sublists 563 563 * sizeof(REGFI_SUBKEY_LIST*)); 564 564 for(i=0; i < num_sublists; i++) … … 575 575 } 576 576 } 577 free(ret_val);577 talloc_free(ret_val); 578 578 579 579 return regfi_merge_subkeylists(num_sublists, sublists, strict); … … 590 590 { 591 591 REGFI_SUBKEY_LIST* ret_val; 592 uint32 i, cell_length, length, elem_size ;593 uint8* elements ;592 uint32 i, cell_length, length, elem_size, read_len; 593 uint8* elements = NULL; 594 594 uint8 buf[REGFI_SUBKEY_LIST_MIN_LEN]; 595 595 bool unalloc; … … 631 631 } 632 632 633 ret_val = (REGFI_SUBKEY_LIST*)zalloc(sizeof(REGFI_SUBKEY_LIST));633 ret_val = talloc(NULL, REGFI_SUBKEY_LIST); 634 634 if(ret_val == NULL) 635 635 return NULL; … … 652 652 offset); 653 653 if(strict) 654 { 655 free(ret_val); 656 return NULL; 657 } 654 goto fail; 658 655 length = cell_length - REGFI_SUBKEY_LIST_MIN_LEN - sizeof(uint32); 659 656 } 660 657 661 ret_val->elements 662 = (REGFI_SUBKEY_LIST_ELEM*)zalloc(ret_val->num_children 663 * sizeof(REGFI_SUBKEY_LIST_ELEM)); 658 ret_val->elements = talloc_array(ret_val, REGFI_SUBKEY_LIST_ELEM, 659 ret_val->num_children); 664 660 if(ret_val->elements == NULL) 665 { 666 free(ret_val); 667 return NULL; 668 } 669 670 elements = (uint8*)zalloc(length); 661 goto fail; 662 663 elements = (uint8*)malloc(length); 671 664 if(elements == NULL) 672 { 673 free(ret_val->elements); 674 free(ret_val); 675 return NULL; 676 } 677 678 if(regfi_read(file->fd, elements, &length) != 0 679 || length != elem_size*ret_val->num_children) 680 { 681 free(ret_val->elements); 682 free(ret_val); 683 return NULL; 684 } 665 goto fail; 666 667 read_len = length; 668 if(regfi_read(file->fd, elements, &read_len) != 0 || read_len != length) 669 goto fail; 685 670 686 671 if(elem_size == sizeof(uint32)) … … 703 688 704 689 return ret_val; 690 691 fail: 692 if(elements != NULL) 693 free(elements); 694 talloc_free(ret_val); 695 return NULL; 705 696 } 706 697 … … 717 708 if(lists == NULL) 718 709 return NULL; 719 ret_val = (REGFI_SUBKEY_LIST*)zalloc(sizeof(REGFI_SUBKEY_LIST));710 ret_val = talloc(NULL, REGFI_SUBKEY_LIST); 720 711 721 712 if(ret_val == NULL) … … 733 724 if(ret_val->num_keys > 0) 734 725 { 735 ret_val->elements = 736 (REGFI_SUBKEY_LIST_ELEM*)zalloc(sizeof(REGFI_SUBKEY_LIST_ELEM) 737 * ret_val->num_keys); 726 ret_val->elements = talloc_array(ret_val, REGFI_SUBKEY_LIST_ELEM, 727 ret_val->num_keys); 738 728 k=0; 739 729 … … 746 736 for(j=0; j < lists[i]->num_keys; j++) 747 737 { 748 ret_val->elements[k].hash =lists[i]->elements[j].hash;749 ret_val->elements[k++].offset =lists[i]->elements[j].offset;738 ret_val->elements[k].hash = lists[i]->elements[j].hash; 739 ret_val->elements[k++].offset = lists[i]->elements[j].offset; 750 740 } 751 741 } … … 789 779 } 790 780 791 /* ret_val = (REGFI_SK_REC*)zalloc(sizeof(REGFI_SK_REC));*/792 781 ret_val = talloc(NULL, REGFI_SK_REC); 793 782 if(ret_val == NULL) … … 903 892 904 893 read_len = num_values*sizeof(uint32); 905 ret_val = (REGFI_VALUE_LIST*)malloc(sizeof(REGFI_VALUE_LIST));894 ret_val = talloc(NULL, REGFI_VALUE_LIST); 906 895 if(ret_val == NULL) 907 896 return NULL; 908 897 909 ret_val->elements = (REGFI_VALUE_LIST_ELEM*) malloc(read_len);898 ret_val->elements = (REGFI_VALUE_LIST_ELEM*)talloc_size(ret_val, read_len); 910 899 if(ret_val->elements == NULL) 911 900 { 912 free(ret_val);901 talloc_free(ret_val); 913 902 return NULL; 914 903 } … … 921 910 regfi_add_message(file, REGFI_MSG_ERROR, "Failed to read value pointers" 922 911 " while parsing value list at offset 0x%.8X.", offset); 923 free(ret_val->elements); 924 free(ret_val); 912 talloc_free(ret_val); 925 913 return NULL; 926 914 } … … 942 930 " (0x%.8X) found while parsing value list at offset" 943 931 " 0x%.8X.", ret_val->elements[i], offset); 944 free(ret_val->elements); 945 free(ret_val); 932 talloc_free(ret_val); 946 933 return NULL; 947 934 } … … 956 943 /****************************************************************************** 957 944 ******************************************************************************/ 958 REGFI_VK_REC* regfi_load_value(REGFI_FILE* file, uint32 offset, 959 bool strict) 945 REGFI_VK_REC* regfi_load_value(REGFI_FILE* file, uint32 offset, bool strict) 960 946 { 961 947 REGFI_VK_REC* ret_val = NULL; … … 1009 995 ret_val->offset); 1010 996 } 997 else 998 talloc_steal(ret_val, ret_val->data); 1011 999 } 1012 1000 … … 1076 1064 if(strict) 1077 1065 { 1078 free(nk);1066 regfi_free_key(nk); 1079 1067 return NULL; 1080 1068 } … … 1095 1083 if(strict) 1096 1084 { 1097 free(nk);1085 regfi_free_key(nk); 1098 1086 return NULL; 1099 1087 } 1100 1088 } 1089 talloc_steal(nk, nk->values); 1101 1090 } 1102 1091 } … … 1109 1098 sub_hbin = regfi_lookup_hbin(file, nk->subkeys_off); 1110 1099 1111 if 1100 if(sub_hbin == NULL) 1112 1101 { 1113 1102 if(strict) 1114 1103 { 1115 regfi_ key_free(nk);1104 regfi_free_key(nk); 1116 1105 return NULL; 1117 1106 } … … 1132 1121 nk->num_subkeys = 0; 1133 1122 } 1123 talloc_steal(nk, nk->subkeys); 1134 1124 } 1135 1125 } … … 1214 1204 *root_offset = nk->offset; 1215 1205 } 1216 free(nk);1206 regfi_free_key(nk); 1217 1207 } 1218 1208 } … … 1267 1257 { 1268 1258 /* fprintf(stderr, "regfi_open: Failed to create HBIN list.\n"); */ 1269 range_list_free(rb->hbins);1270 1259 close(fd); 1271 free(rb); 1272 return NULL; 1273 } 1274 1260 talloc_free(rb); 1261 return NULL; 1262 } 1263 talloc_steal(rb, rb->hbins); 1264 1275 1265 rla = true; 1276 1266 hbin_off = REGFI_REGF_SIZE; … … 1292 1282 1293 1283 /* Cache an unlimited number of SK records. Typically there are very few. */ 1294 rb->sk_cache = lru_cache_create_ctx( NULL, 0, cache_secret, true);1284 rb->sk_cache = lru_cache_create_ctx(rb, 0, cache_secret, true); 1295 1285 1296 1286 /* Default message mask */ … … 1320 1310 lru_cache_destroy(file->sk_cache); 1321 1311 1322 free(file);1312 talloc_free(file); 1323 1313 return close(fd); 1324 1314 } … … 1361 1351 /****************************************************************************** 1362 1352 *****************************************************************************/ 1363 void regfi_key_free(REGFI_NK_REC* nk) 1364 { 1365 if((nk->values != NULL) && (nk->values_off!=REGFI_OFFSET_NONE)) 1366 { 1367 if(nk->values->elements != NULL) 1368 free(nk->values->elements); 1369 free(nk->values); 1370 } 1371 1353 void regfi_free_key(REGFI_NK_REC* nk) 1354 { 1372 1355 regfi_subkeylist_free(nk->subkeys); 1373 1374 if(nk->keyname != NULL) 1375 free(nk->keyname); 1376 if(nk->classname != NULL) 1377 free(nk->classname); 1378 1379 /* XXX: not freeing sec_desc because these are cached. This needs to be reviewed. */ 1380 free(nk); 1356 talloc_free(nk); 1357 } 1358 1359 1360 /****************************************************************************** 1361 *****************************************************************************/ 1362 void regfi_free_value(REGFI_VK_REC* vk) 1363 { 1364 talloc_free(vk); 1381 1365 } 1382 1366 … … 1388 1372 if(list != NULL) 1389 1373 { 1390 free(list->elements); 1391 free(list); 1374 talloc_free(list); 1392 1375 } 1393 1376 } … … 1399 1382 { 1400 1383 REGFI_NK_REC* root; 1401 REGFI_ITERATOR* ret_val = (REGFI_ITERATOR*)malloc(sizeof(REGFI_ITERATOR));1384 REGFI_ITERATOR* ret_val = talloc(NULL, REGFI_ITERATOR); 1402 1385 if(ret_val == NULL) 1403 1386 return NULL; … … 1406 1389 if(root == NULL) 1407 1390 { 1408 free(ret_val);1391 talloc_free(ret_val); 1409 1392 return NULL; 1410 1393 } … … 1413 1396 if(ret_val->key_positions == NULL) 1414 1397 { 1415 free(ret_val); 1416 return NULL; 1417 } 1398 talloc_free(ret_val); 1399 return NULL; 1400 } 1401 talloc_steal(ret_val, ret_val->key_positions); 1418 1402 1419 1403 ret_val->f = fh; … … 1430 1414 void regfi_iterator_free(REGFI_ITERATOR* i) 1431 1415 { 1432 REGFI_ITER_POSITION* cur; 1433 1434 if(i->cur_key != NULL) 1435 regfi_key_free(i->cur_key); 1436 1437 while((cur = (REGFI_ITER_POSITION*)void_stack_pop(i->key_positions)) != NULL) 1438 { 1439 regfi_key_free(cur->nk); 1440 free(cur); 1441 } 1442 1443 void_stack_free(i->key_positions); 1444 free(i); 1416 talloc_free(i); 1445 1417 } 1446 1418 … … 1455 1427 REGFI_ITER_POSITION* pos; 1456 1428 1457 pos = (REGFI_ITER_POSITION*)malloc(sizeof(REGFI_ITER_POSITION));1429 pos = talloc(i->key_positions, REGFI_ITER_POSITION); 1458 1430 if(pos == NULL) 1459 1431 return false; … … 1462 1434 if(subkey == NULL) 1463 1435 { 1464 free(pos);1436 talloc_free(pos); 1465 1437 return false; 1466 1438 } … … 1470 1442 if(!void_stack_push(i->key_positions, pos)) 1471 1443 { 1472 free(pos);1473 regfi_ key_free(subkey);1444 talloc_free(pos); 1445 regfi_free_key(subkey); 1474 1446 return false; 1475 1447 } 1448 talloc_steal(i, subkey); 1476 1449 1477 1450 i->cur_key = subkey; … … 1493 1466 return false; 1494 1467 1495 regfi_ key_free(i->cur_key);1468 regfi_free_key(i->cur_key); 1496 1469 i->cur_key = pos->nk; 1497 1470 i->cur_subkey = pos->cur_subkey; 1498 1471 i->cur_value = 0; 1499 free(pos);1472 talloc_free(pos); 1500 1473 1501 1474 return true; … … 1534 1507 else 1535 1508 { 1536 regfi_ key_free(subkey);1509 regfi_free_key(subkey); 1537 1510 subkey = (REGFI_NK_REC*)regfi_iterator_next_subkey(i); 1538 1511 } … … 1545 1518 } 1546 1519 1547 regfi_ key_free(subkey);1520 regfi_free_key(subkey); 1548 1521 return true; 1549 1522 } … … 1596 1569 /****************************************************************************** 1597 1570 *****************************************************************************/ 1598 constREGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)1571 REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i) 1599 1572 { 1600 1573 i->cur_subkey = 0; … … 1605 1578 /****************************************************************************** 1606 1579 *****************************************************************************/ 1607 constREGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)1580 REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i) 1608 1581 { 1609 1582 uint32 nk_offset; … … 1623 1596 *****************************************************************************/ 1624 1597 /* XXX: some way of indicating reason for failure should be added. */ 1625 constREGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)1626 { 1627 constREGFI_NK_REC* subkey;1598 REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i) 1599 { 1600 REGFI_NK_REC* subkey; 1628 1601 1629 1602 i->cur_subkey++; … … 1641 1614 bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name) 1642 1615 { 1643 constREGFI_VK_REC* cur;1616 REGFI_VK_REC* cur; 1644 1617 bool found = false; 1645 1618 … … 1657 1630 found = true; 1658 1631 else 1632 { 1633 regfi_free_value(cur); 1659 1634 cur = regfi_iterator_next_value(i); 1635 } 1660 1636 } 1661 1637 … … 1666 1642 /****************************************************************************** 1667 1643 *****************************************************************************/ 1668 constREGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)1644 REGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i) 1669 1645 { 1670 1646 i->cur_value = 0; … … 1675 1651 /****************************************************************************** 1676 1652 *****************************************************************************/ 1677 constREGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)1678 { 1679 constREGFI_VK_REC* ret_val = NULL;1653 REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i) 1654 { 1655 REGFI_VK_REC* ret_val = NULL; 1680 1656 uint32 voffset; 1681 1657 … … 1695 1671 /****************************************************************************** 1696 1672 *****************************************************************************/ 1697 constREGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)1698 { 1699 constREGFI_VK_REC* ret_val;1673 REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i) 1674 { 1675 REGFI_VK_REC* ret_val; 1700 1676 1701 1677 i->cur_value++; … … 1739 1715 REGFI_FILE* ret_val; 1740 1716 1741 ret_val = (REGFI_FILE*)zalloc(sizeof(REGFI_FILE));1717 ret_val = talloc(NULL, REGFI_FILE); 1742 1718 if(ret_val == NULL) 1743 1719 return NULL; 1744 1720 1745 1721 ret_val->fd = fd; 1746 1722 ret_val->sk_cache = NULL; 1723 ret_val->last_message = NULL; 1724 ret_val->hbins = NULL; 1725 1747 1726 length = REGFI_REGF_SIZE; 1748 if((regfi_read(fd, file_header, &length)) != 0 1749 || length != REGFI_REGF_SIZE) 1750 { 1751 free(ret_val); 1752 return NULL; 1753 } 1754 1727 if((regfi_read(fd, file_header, &length)) != 0 || length != REGFI_REGF_SIZE) 1728 goto fail; 1729 1755 1730 ret_val->checksum = IVAL(file_header, 0x1FC); 1756 1731 ret_val->computed_checksum = regfi_compute_header_checksum(file_header); 1757 1732 if (strict && (ret_val->checksum != ret_val->computed_checksum)) 1758 { 1759 free(ret_val); 1760 return NULL; 1761 } 1733 goto fail; 1762 1734 1763 1735 memcpy(ret_val->magic, file_header, REGFI_REGF_MAGIC_SIZE); 1764 if(strict && (memcmp(ret_val->magic, "regf", REGFI_REGF_MAGIC_SIZE) != 0)) 1765 { 1766 free(ret_val); 1767 return NULL; 1736 if(memcmp(ret_val->magic, "regf", REGFI_REGF_MAGIC_SIZE) != 0) 1737 { 1738 if(strict) 1739 goto fail; 1740 regfi_add_message(ret_val, REGFI_MSG_WARN, "Magic number mismatch " 1741 "(%.2X %.2X %.2X %.2X) while parsing hive header", 1742 ret_val->magic[0],ret_val->magic[1], 1743 ret_val->magic[2], ret_val->magic[3]); 1768 1744 } 1769 1745 … … 1785 1761 1786 1762 return ret_val; 1763 1764 fail: 1765 talloc_free(ret_val); 1766 return NULL; 1787 1767 } 1788 1768 … … 1891 1871 } 1892 1872 1893 ret_val = (REGFI_NK_REC*)zalloc(sizeof(REGFI_NK_REC));1873 ret_val = talloc(NULL, REGFI_NK_REC); 1894 1874 if(ret_val == NULL) 1895 1875 { … … 1899 1879 } 1900 1880 1881 ret_val->values = NULL; 1882 ret_val->subkeys = NULL; 1901 1883 ret_val->offset = offset; 1902 1884 ret_val->cell_size = cell_length; … … 1909 1891 regfi_add_message(file, REGFI_MSG_WARN, "A length check failed while" 1910 1892 " parsing NK record at offset 0x%.8X.", offset); 1911 free(ret_val);1893 talloc_free(ret_val); 1912 1894 return NULL; 1913 1895 } … … 1969 1951 regfi_add_message(file, REGFI_MSG_ERROR, "Contents too large for cell" 1970 1952 " while parsing NK record at offset 0x%.8X.", offset); 1971 free(ret_val);1953 talloc_free(ret_val); 1972 1954 return NULL; 1973 1955 } … … 1987 1969 } 1988 1970 1989 ret_val->keyname = (char*)zalloc(sizeof(char)*(ret_val->name_length+1));1971 ret_val->keyname = talloc_array(ret_val, char, ret_val->name_length+1); 1990 1972 if(ret_val->keyname == NULL) 1991 1973 { 1992 free(ret_val);1974 talloc_free(ret_val); 1993 1975 return NULL; 1994 1976 } … … 2001 1983 regfi_add_message(file, REGFI_MSG_ERROR, "Failed to read key name" 2002 1984 " while parsing NK record at offset 0x%.8X.", offset); 2003 free(ret_val->keyname); 2004 free(ret_val); 1985 talloc_free(ret_val); 2005 1986 return NULL; 2006 1987 } 2007 1988 ret_val->keyname[ret_val->name_length] = '\0'; 2008 1989 1990 /* XXX: This linking should be moved up to regfi_load_key */ 2009 1991 if(ret_val->classname_off != REGFI_OFFSET_NONE) 2010 1992 { … … 2031 2013 " name while parsing NK record at offset 0x%.8X.", 2032 2014 offset); 2033 return NULL; 2034 } 2015 } 2016 else 2017 talloc_steal(ret_val, ret_val->classname); 2035 2018 } 2036 2019 … … 2084 2067 } 2085 2068 2086 ret_val = (char*)zalloc(*name_length);2069 ret_val = talloc_array(NULL, char, *name_length); 2087 2070 if(ret_val != NULL) 2088 2071 { … … 2093 2076 regfi_add_message(file, REGFI_MSG_ERROR, "Could not read class name" 2094 2077 " while parsing class name at offset 0x%.8X.", offset); 2095 free(ret_val);2078 talloc_free(ret_val); 2096 2079 return NULL; 2097 2080 } … … 2121 2104 } 2122 2105 2123 ret_val = (REGFI_VK_REC*)zalloc(sizeof(REGFI_VK_REC));2106 ret_val = talloc(NULL, REGFI_VK_REC); 2124 2107 if(ret_val == NULL) 2125 2108 return NULL; … … 2127 2110 ret_val->offset = offset; 2128 2111 ret_val->cell_size = cell_length; 2129 2112 ret_val->data = NULL; 2113 ret_val->valuename = NULL; 2114 2130 2115 if(ret_val->cell_size > max_size) 2131 2116 ret_val->cell_size = max_size & 0xFFFFFFF8; … … 2135 2120 regfi_add_message(file, REGFI_MSG_WARN, "Invalid cell size encountered" 2136 2121 " while parsing VK record at offset 0x%.8X.", offset); 2137 free(ret_val);2122 talloc_free(ret_val); 2138 2123 return NULL; 2139 2124 } … … 2149 2134 regfi_add_message(file, REGFI_MSG_WARN, "Magic number mismatch" 2150 2135 " while parsing VK record at offset 0x%.8X.", offset); 2151 free(ret_val);2136 talloc_free(ret_val); 2152 2137 return NULL; 2153 2138 } … … 2171 2156 if(strict) 2172 2157 { 2173 free(ret_val);2158 talloc_free(ret_val); 2174 2159 return NULL; 2175 2160 } … … 2183 2168 cell_length+=8; 2184 2169 2185 ret_val->valuename = (char*)zalloc(sizeof(char)*(ret_val->name_length+1));2170 ret_val->valuename = talloc_array(ret_val, char, ret_val->name_length+1); 2186 2171 if(ret_val->valuename == NULL) 2187 2172 { 2188 free(ret_val);2173 talloc_free(ret_val); 2189 2174 return NULL; 2190 2175 } … … 2196 2181 regfi_add_message(file, REGFI_MSG_ERROR, "Could not read value name" 2197 2182 " while parsing VK record at offset 0x%.8X.", offset); 2198 free(ret_val->valuename); 2199 free(ret_val); 2183 talloc_free(ret_val); 2200 2184 return NULL; 2201 2185 } … … 2238 2222 } 2239 2223 2240 if((ret_val = (uint8*)zalloc(sizeof(uint8)*length)) == NULL)2224 if((ret_val = talloc_array(NULL, uint8_t, length)) == NULL) 2241 2225 return NULL; 2242 2226 … … 2289 2273 } 2290 2274 2291 if((ret_val = (uint8*)zalloc(sizeof(uint8)*length)) == NULL)2275 if((ret_val = talloc_array(NULL, uint8_t, length)) == NULL) 2292 2276 return NULL; 2293 2277 … … 2298 2282 regfi_add_message(file, REGFI_MSG_ERROR, "Could not read data block while" 2299 2283 " parsing data record at offset 0x%.8X.", offset); 2300 free(ret_val);2284 talloc_free(ret_val); 2301 2285 return NULL; 2302 2286 } -
trunk/lib/void_stack.c
r147 r150 4 4 * leaks. 5 5 * 6 * Copyright (C) 2005,2007 Timothy D. Morgan6 * Copyright (C) 2005,2007,2009 Timothy D. Morgan 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify … … 26 26 void_stack* void_stack_new(unsigned short max_size) 27 27 { 28 void_stack* ret_val = (void_stack*)malloc(sizeof(void_stack));28 void_stack* ret_val = talloc(NULL, void_stack); 29 29 30 30 if (ret_val != NULL) 31 31 { 32 32 memset(ret_val, 0, sizeof(*ret_val)); 33 ret_val->elements = (void**)malloc(max_size*sizeof(void*));33 ret_val->elements = talloc_array(ret_val, void*, max_size); 34 34 if (ret_val->elements == NULL) 35 35 { 36 free(ret_val);36 talloc_free(ret_val); 37 37 ret_val = NULL; 38 38 } … … 90 90 void void_stack_free(void_stack* stack) 91 91 { 92 free(stack->elements); 93 free(stack); 92 talloc_free(stack); 94 93 } 95 94 … … 100 99 for(i=0; i < stack->top; i++) 101 100 free(stack->elements[i]); 102 free(stack->elements); 103 free(stack); 101 talloc_free(stack); 104 102 } 105 103 … … 154 152 if(stack != NULL) 155 153 { 156 ret_val = (void_stack_iterator*)malloc(sizeof(void_stack_iterator));154 ret_val = talloc(stack, void_stack_iterator); 157 155 if (ret_val != NULL) 158 156 { … … 168 166 void void_stack_iterator_free(void_stack_iterator* iter) 169 167 { 170 free(iter);168 talloc_free(iter); 171 169 } 172 170 -
trunk/src/reglookup-recover.c
r149 r150 15 15 * You should have received a copy of the GNU General Public License 16 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 18 * 19 19 * $Id$ … … 84 84 quoted_name = malloc(1*sizeof(char)); 85 85 if(quoted_name == NULL) 86 bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n"); 86 bailOut(REGLOOKUP_EXIT_OSERR, 87 "ERROR: Could not allocate sufficient memory.\n"); 87 88 quoted_name[0] = '\0'; 88 89 … … 297 298 virt_offset = cur_ancestor->parent_off; 298 299 299 path_element = (struct name_holder*)malloc(sizeof(struct name_holder));300 path_element = talloc(path_stack, struct name_holder); 300 301 if(path_element != NULL) 301 302 path_element->quoted_name = quote_string(cur_ancestor->keyname, … … 305 306 || !void_stack_push(path_stack, path_element)) 306 307 { 307 free(cur_ancestor->keyname);308 free(cur_ancestor);309 void_stack_free _deep(path_stack);308 /* XXX: Need to add a warning here */ 309 regfi_free_key(cur_ancestor); 310 void_stack_free(path_stack); 310 311 return NULL; 311 312 } … … 318 319 ret_val_size += path_element->length + 1; 319 320 320 regfi_ key_free(cur_ancestor);321 regfi_free_key(cur_ancestor); 321 322 } 322 323 } … … 328 329 if(ret_val == NULL) 329 330 { 330 void_stack_free _deep(path_stack);331 void_stack_free(path_stack); 331 332 return NULL; 332 333 } … … 340 341 ret_val_used += path_element->length + 1; 341 342 free(path_element->quoted_name); 342 free(path_element);343 talloc_free(path_element); 343 344 } 344 345 void_stack_free(path_stack); … … 532 533 REGFI_NK_REC* key; 533 534 uint32 i, j; 535 int error_code = 0; 534 536 535 537 for(i=0; i < range_list_size(unalloc_cells); i++) … … 550 552 { 551 553 fprintf(stderr, "ERROR: Couldn't add key to unalloc_keys.\n"); 552 return 20; 554 error_code = 20; 555 goto fail; 553 556 } 557 talloc_steal(unalloc_keys, key); 554 558 j+=key->cell_size-8; 555 559 } … … 561 565 cur_elem = range_list_get(unalloc_keys, i); 562 566 if(!removeRange(unalloc_cells, cur_elem->offset, cur_elem->length)) 563 return 30; 567 { 568 error_code = 30; 569 goto fail; 570 } 564 571 } 565 572 566 573 return 0; 574 575 fail: 576 regfi_free_key(key); 577 return error_code; 567 578 } 568 579 … … 611 622 * so prune it. 612 623 */ 613 free(nk->values->elements); 614 free(nk->values); 624 talloc_free(nk->values); 615 625 nk->values = NULL; 616 626 } … … 639 649 vk->cell_size, vk)) 640 650 { 641 free(vk);651 talloc_free(vk); 642 652 return 30; 643 653 } … … 647 657 } 648 658 else 649 free(vk);659 talloc_free(vk); 650 660 } 651 661 } -
trunk/src/reglookup.c
r147 r150 275 275 void printValueList(REGFI_ITERATOR* iter, char* prefix) 276 276 { 277 constREGFI_VK_REC* value;277 REGFI_VK_REC* value; 278 278 279 279 value = regfi_iterator_first_value(iter); … … 282 282 if(!type_filter_enabled || (value->type == type_filter)) 283 283 printValue(value, prefix); 284 regfi_free_value(value); 284 285 value = regfi_iterator_next_value(iter); 285 286 printMsgs(iter->f); … … 373 374 const REGFI_NK_REC* root = NULL; 374 375 const REGFI_NK_REC* cur = NULL; 375 constREGFI_NK_REC* sub = NULL;376 REGFI_NK_REC* sub = NULL; 376 377 char* path = NULL; 377 378 int key_type = regfi_type_str2val("KEY"); … … 418 419 bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: unexpected NULL for key.\n"); 419 420 } 420 421 421 422 sub = regfi_iterator_next_subkey(iter); 422 423 } … … 433 434 } 434 435 435 cur = sub; 436 cur = regfi_iterator_cur_key(iter); 437 regfi_free_key(sub); 436 438 sub = regfi_iterator_first_subkey(iter); 437 439 print_this = true; … … 456 458 int retrievePath(REGFI_ITERATOR* iter, char** path) 457 459 { 458 constREGFI_VK_REC* value;460 REGFI_VK_REC* value; 459 461 char* tmp_path_joined; 460 462 const char** tmp_path; … … 511 513 printValue(value, tmp_path_joined); 512 514 515 regfi_free_value(value); 513 516 free(tmp_path); 514 517 free(tmp_path_joined);
Note: See TracChangeset
for help on using the changeset viewer.