diff options
author | tdeval <> | 2003-05-14 15:41:51 +0000 |
---|---|---|
committer | tdeval <> | 2003-05-14 15:41:51 +0000 |
commit | d26c069afe2173a0a8048c2e1929867e3a83535a (patch) | |
tree | 66945c7646f1de4be6addc96696e8eef9b60f837 /src/lib | |
parent | 8d73c41588c200aea039113ab19d0f18ce7ab3e6 (diff) | |
download | openbsd-d26c069afe2173a0a8048c2e1929867e3a83535a.tar.gz openbsd-d26c069afe2173a0a8048c2e1929867e3a83535a.tar.bz2 openbsd-d26c069afe2173a0a8048c2e1929867e3a83535a.zip |
Pointer cleaning. ok ian@, tedu@, krw@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/stdlib/malloc.c | 133 |
1 files changed, 67 insertions, 66 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index c8aef635d4..d1dba276f1 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
@@ -8,7 +8,7 @@ | |||
8 | */ | 8 | */ |
9 | 9 | ||
10 | #if defined(LIBC_SCCS) && !defined(lint) | 10 | #if defined(LIBC_SCCS) && !defined(lint) |
11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.54 2003/01/14 02:27:16 millert Exp $"; | 11 | static char rcsid[] = "$OpenBSD: malloc.c,v 1.55 2003/05/14 15:41:51 tdeval Exp $"; |
12 | #endif /* LIBC_SCCS and not lint */ | 12 | #endif /* LIBC_SCCS and not lint */ |
13 | 13 | ||
14 | /* | 14 | /* |
@@ -237,7 +237,7 @@ static char *malloc_func; | |||
237 | /* Macro for mmap */ | 237 | /* Macro for mmap */ |
238 | #define MMAP(size) \ | 238 | #define MMAP(size) \ |
239 | mmap((void *)0, (size), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, \ | 239 | mmap((void *)0, (size), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, \ |
240 | MMAP_FD, (off_t)0); | 240 | MMAP_FD, (off_t)0) |
241 | 241 | ||
242 | /* | 242 | /* |
243 | * Necessary function declarations | 243 | * Necessary function declarations |
@@ -363,7 +363,7 @@ malloc_exit() | |||
363 | { | 363 | { |
364 | FILE *fd = fopen("malloc.out", "a"); | 364 | FILE *fd = fopen("malloc.out", "a"); |
365 | char *q = "malloc() warning: Couldn't dump stats.\n"; | 365 | char *q = "malloc() warning: Couldn't dump stats.\n"; |
366 | if (fd) { | 366 | if (fd != NULL) { |
367 | malloc_dump(fd); | 367 | malloc_dump(fd); |
368 | fclose(fd); | 368 | fclose(fd); |
369 | } else | 369 | } else |
@@ -387,24 +387,24 @@ map_pages(pages) | |||
387 | #ifdef MALLOC_EXTRA_SANITY | 387 | #ifdef MALLOC_EXTRA_SANITY |
388 | wrterror("(ES): overflow in map_pages fails\n"); | 388 | wrterror("(ES): overflow in map_pages fails\n"); |
389 | #endif /* MALLOC_EXTRA_SANITY */ | 389 | #endif /* MALLOC_EXTRA_SANITY */ |
390 | return 0; | 390 | return (NULL); |
391 | } | 391 | } |
392 | tail = result + pages; | 392 | tail = result + pages; |
393 | 393 | ||
394 | if (brk(tail)) { | 394 | if ((int)brk(tail) == -1) { |
395 | #ifdef MALLOC_EXTRA_SANITY | 395 | #ifdef MALLOC_EXTRA_SANITY |
396 | wrterror("(ES): map_pages fails\n"); | 396 | wrterror("(ES): map_pages fails\n"); |
397 | #endif /* MALLOC_EXTRA_SANITY */ | 397 | #endif /* MALLOC_EXTRA_SANITY */ |
398 | return 0; | 398 | return (NULL); |
399 | } | 399 | } |
400 | 400 | ||
401 | last_index = ptr2index(tail) - 1; | 401 | last_index = ptr2index(tail) - 1; |
402 | malloc_brk = tail; | 402 | malloc_brk = tail; |
403 | 403 | ||
404 | if ((last_index+1) >= malloc_ninfo && !extend_pgdir(last_index)) | 404 | if ((last_index+1) >= malloc_ninfo && extend_pgdir(last_index) == NULL) |
405 | return 0; | 405 | return (NULL); |
406 | 406 | ||
407 | return result; | 407 | return (result); |
408 | } | 408 | } |
409 | 409 | ||
410 | /* | 410 | /* |
@@ -443,7 +443,7 @@ extend_pgdir(index) | |||
443 | /* Get new pages */ | 443 | /* Get new pages */ |
444 | new = (struct pginfo**) MMAP(i * malloc_pagesize); | 444 | new = (struct pginfo**) MMAP(i * malloc_pagesize); |
445 | if (new == MAP_FAILED) | 445 | if (new == MAP_FAILED) |
446 | return 0; | 446 | return (0); |
447 | 447 | ||
448 | /* Copy the old stuff */ | 448 | /* Copy the old stuff */ |
449 | memcpy(new, page_dir, | 449 | memcpy(new, page_dir, |
@@ -458,7 +458,7 @@ extend_pgdir(index) | |||
458 | 458 | ||
459 | /* Now free the old stuff */ | 459 | /* Now free the old stuff */ |
460 | munmap(old, oldlen); | 460 | munmap(old, oldlen); |
461 | return 1; | 461 | return (1); |
462 | } | 462 | } |
463 | 463 | ||
464 | /* | 464 | /* |
@@ -494,7 +494,7 @@ malloc_init () | |||
494 | } else if (i == 2) { | 494 | } else if (i == 2) { |
495 | p = malloc_options; | 495 | p = malloc_options; |
496 | } | 496 | } |
497 | for (; p && *p; p++) { | 497 | for (; p != NULL && *p != '\0'; p++) { |
498 | switch (*p) { | 498 | switch (*p) { |
499 | case '>': malloc_cache <<= 1; break; | 499 | case '>': malloc_cache <<= 1; break; |
500 | case '<': malloc_cache >>= 1; break; | 500 | case '<': malloc_cache >>= 1; break; |
@@ -586,14 +586,14 @@ static void * | |||
586 | malloc_pages(size) | 586 | malloc_pages(size) |
587 | size_t size; | 587 | size_t size; |
588 | { | 588 | { |
589 | void *p, *delay_free = 0; | 589 | void *p, *delay_free = NULL; |
590 | int i; | 590 | int i; |
591 | struct pgfree *pf; | 591 | struct pgfree *pf; |
592 | u_long index; | 592 | u_long index; |
593 | 593 | ||
594 | size = pageround(size); | 594 | size = pageround(size); |
595 | 595 | ||
596 | p = 0; | 596 | p = NULL; |
597 | /* Look for free pages before asking for more */ | 597 | /* Look for free pages before asking for more */ |
598 | for(pf = free_list.next; pf; pf = pf->next) { | 598 | for(pf = free_list.next; pf; pf = pf->next) { |
599 | 599 | ||
@@ -619,7 +619,7 @@ malloc_pages(size) | |||
619 | 619 | ||
620 | if (pf->size == size) { | 620 | if (pf->size == size) { |
621 | p = pf->page; | 621 | p = pf->page; |
622 | if (pf->next) | 622 | if (pf->next != NULL) |
623 | pf->next->prev = pf->prev; | 623 | pf->next->prev = pf->prev; |
624 | pf->prev->next = pf->next; | 624 | pf->prev->next = pf->next; |
625 | delay_free = pf; | 625 | delay_free = pf; |
@@ -633,17 +633,17 @@ malloc_pages(size) | |||
633 | } | 633 | } |
634 | 634 | ||
635 | #ifdef MALLOC_EXTRA_SANITY | 635 | #ifdef MALLOC_EXTRA_SANITY |
636 | if (p && page_dir[ptr2index(p)] != MALLOC_FREE) | 636 | if (p != NULL && page_dir[ptr2index(p)] != MALLOC_FREE) |
637 | wrterror("(ES): allocated non-free page on free-list\n"); | 637 | wrterror("(ES): allocated non-free page on free-list\n"); |
638 | #endif /* MALLOC_EXTRA_SANITY */ | 638 | #endif /* MALLOC_EXTRA_SANITY */ |
639 | 639 | ||
640 | size >>= malloc_pageshift; | 640 | size >>= malloc_pageshift; |
641 | 641 | ||
642 | /* Map new pages */ | 642 | /* Map new pages */ |
643 | if (!p) | 643 | if (p == NULL) |
644 | p = map_pages(size); | 644 | p = map_pages(size); |
645 | 645 | ||
646 | if (p) { | 646 | if (p != NULL) { |
647 | 647 | ||
648 | index = ptr2index(p); | 648 | index = ptr2index(p); |
649 | page_dir[index] = MALLOC_FIRST; | 649 | page_dir[index] = MALLOC_FIRST; |
@@ -655,13 +655,13 @@ malloc_pages(size) | |||
655 | } | 655 | } |
656 | 656 | ||
657 | if (delay_free) { | 657 | if (delay_free) { |
658 | if (!px) | 658 | if (px == NULL) |
659 | px = delay_free; | 659 | px = delay_free; |
660 | else | 660 | else |
661 | ifree(delay_free); | 661 | ifree(delay_free); |
662 | } | 662 | } |
663 | 663 | ||
664 | return p; | 664 | return (p); |
665 | } | 665 | } |
666 | 666 | ||
667 | /* | 667 | /* |
@@ -678,8 +678,8 @@ malloc_make_chunks(bits) | |||
678 | 678 | ||
679 | /* Allocate a new bucket */ | 679 | /* Allocate a new bucket */ |
680 | pp = malloc_pages((size_t)malloc_pagesize); | 680 | pp = malloc_pages((size_t)malloc_pagesize); |
681 | if (!pp) | 681 | if (pp == NULL) |
682 | return 0; | 682 | return (0); |
683 | 683 | ||
684 | /* Find length of admin structure */ | 684 | /* Find length of admin structure */ |
685 | l = sizeof *bp - sizeof(u_long); | 685 | l = sizeof *bp - sizeof(u_long); |
@@ -697,9 +697,9 @@ malloc_make_chunks(bits) | |||
697 | bp = (struct pginfo *)pp; | 697 | bp = (struct pginfo *)pp; |
698 | } else { | 698 | } else { |
699 | bp = (struct pginfo *)imalloc(l); | 699 | bp = (struct pginfo *)imalloc(l); |
700 | if (!bp) { | 700 | if (bp == NULL) { |
701 | ifree(pp); | 701 | ifree(pp); |
702 | return 0; | 702 | return (0); |
703 | } | 703 | } |
704 | } | 704 | } |
705 | 705 | ||
@@ -718,7 +718,7 @@ malloc_make_chunks(bits) | |||
718 | if (k < 0) { | 718 | if (k < 0) { |
719 | ifree(pp); | 719 | ifree(pp); |
720 | ifree(bp); | 720 | ifree(bp); |
721 | return 0; | 721 | return (0); |
722 | } | 722 | } |
723 | } else { | 723 | } else { |
724 | bp->size = (1UL<<bits); | 724 | bp->size = (1UL<<bits); |
@@ -757,7 +757,7 @@ malloc_make_chunks(bits) | |||
757 | 757 | ||
758 | /* MALLOC_UNLOCK */ | 758 | /* MALLOC_UNLOCK */ |
759 | 759 | ||
760 | return 1; | 760 | return (1); |
761 | } | 761 | } |
762 | 762 | ||
763 | /* | 763 | /* |
@@ -789,8 +789,8 @@ malloc_bytes(size) | |||
789 | } | 789 | } |
790 | 790 | ||
791 | /* If it's empty, make a page more of that size chunks */ | 791 | /* If it's empty, make a page more of that size chunks */ |
792 | if (!page_dir[j] && !malloc_make_chunks(j)) | 792 | if (page_dir[j] == NULL && malloc_make_chunks(j) == NULL) |
793 | return 0; | 793 | return (NULL); |
794 | 794 | ||
795 | bp = page_dir[j]; | 795 | bp = page_dir[j]; |
796 | 796 | ||
@@ -810,7 +810,7 @@ malloc_bytes(size) | |||
810 | /* If there are no more free, remove from free-list */ | 810 | /* If there are no more free, remove from free-list */ |
811 | if (!--bp->free) { | 811 | if (!--bp->free) { |
812 | page_dir[j] = bp->next; | 812 | page_dir[j] = bp->next; |
813 | bp->next = 0; | 813 | bp->next = NULL; |
814 | } | 814 | } |
815 | 815 | ||
816 | /* Adjust to the real offset of that chunk */ | 816 | /* Adjust to the real offset of that chunk */ |
@@ -820,7 +820,7 @@ malloc_bytes(size) | |||
820 | if (malloc_junk && bp->size != 0) | 820 | if (malloc_junk && bp->size != 0) |
821 | memset((char *)bp->page + k, SOME_JUNK, bp->size); | 821 | memset((char *)bp->page + k, SOME_JUNK, bp->size); |
822 | 822 | ||
823 | return (u_char *)bp->page + k; | 823 | return ((u_char *)bp->page + k); |
824 | } | 824 | } |
825 | 825 | ||
826 | /* | 826 | /* |
@@ -839,19 +839,19 @@ imalloc(size) | |||
839 | abort(); | 839 | abort(); |
840 | 840 | ||
841 | if ((size + malloc_pagesize) < size) /* Check for overflow */ | 841 | if ((size + malloc_pagesize) < size) /* Check for overflow */ |
842 | result = 0; | 842 | result = NULL; |
843 | else if (size <= malloc_maxsize) | 843 | else if (size <= malloc_maxsize) |
844 | result = malloc_bytes(size); | 844 | result = malloc_bytes(size); |
845 | else | 845 | else |
846 | result = malloc_pages(size); | 846 | result = malloc_pages(size); |
847 | 847 | ||
848 | if (malloc_abort && !result) | 848 | if (malloc_abort && result == NULL) |
849 | wrterror("allocation failed.\n"); | 849 | wrterror("allocation failed.\n"); |
850 | 850 | ||
851 | if (malloc_zero && result) | 851 | if (malloc_zero && result != NULL) |
852 | memset(result, 0, size); | 852 | memset(result, 0, size); |
853 | 853 | ||
854 | return result; | 854 | return (result); |
855 | } | 855 | } |
856 | 856 | ||
857 | /* | 857 | /* |
@@ -872,19 +872,19 @@ irealloc(ptr, size) | |||
872 | 872 | ||
873 | if (!malloc_started) { | 873 | if (!malloc_started) { |
874 | wrtwarning("malloc() has never been called.\n"); | 874 | wrtwarning("malloc() has never been called.\n"); |
875 | return 0; | 875 | return (NULL); |
876 | } | 876 | } |
877 | 877 | ||
878 | index = ptr2index(ptr); | 878 | index = ptr2index(ptr); |
879 | 879 | ||
880 | if (index < malloc_pageshift) { | 880 | if (index < malloc_pageshift) { |
881 | wrtwarning("junk pointer, too low to make sense.\n"); | 881 | wrtwarning("junk pointer, too low to make sense.\n"); |
882 | return 0; | 882 | return (NULL); |
883 | } | 883 | } |
884 | 884 | ||
885 | if (index > last_index) { | 885 | if (index > last_index) { |
886 | wrtwarning("junk pointer, too high to make sense.\n"); | 886 | wrtwarning("junk pointer, too high to make sense.\n"); |
887 | return 0; | 887 | return (NULL); |
888 | } | 888 | } |
889 | 889 | ||
890 | mp = &page_dir[index]; | 890 | mp = &page_dir[index]; |
@@ -894,11 +894,11 @@ irealloc(ptr, size) | |||
894 | /* Check the pointer */ | 894 | /* Check the pointer */ |
895 | if ((u_long)ptr & malloc_pagemask) { | 895 | if ((u_long)ptr & malloc_pagemask) { |
896 | wrtwarning("modified (page-) pointer.\n"); | 896 | wrtwarning("modified (page-) pointer.\n"); |
897 | return 0; | 897 | return (NULL); |
898 | } | 898 | } |
899 | 899 | ||
900 | /* Find the size in bytes */ | 900 | /* Find the size in bytes */ |
901 | for (osize = malloc_pagesize; *++mp == MALLOC_FOLLOW;) | 901 | for (osize = malloc_pagesize; *(++mp) == MALLOC_FOLLOW;) |
902 | osize += malloc_pagesize; | 902 | osize += malloc_pagesize; |
903 | 903 | ||
904 | if (!malloc_realloc && /* Unless we have to, */ | 904 | if (!malloc_realloc && /* Unless we have to, */ |
@@ -906,7 +906,7 @@ irealloc(ptr, size) | |||
906 | size > (osize - malloc_pagesize)) { /* .. or can free a page, */ | 906 | size > (osize - malloc_pagesize)) { /* .. or can free a page, */ |
907 | if (malloc_junk) | 907 | if (malloc_junk) |
908 | memset((char *)ptr + size, SOME_JUNK, osize-size); | 908 | memset((char *)ptr + size, SOME_JUNK, osize-size); |
909 | return ptr; /* ..don't do anything else. */ | 909 | return (ptr); /* ..don't do anything else. */ |
910 | } | 910 | } |
911 | 911 | ||
912 | } else if (*mp >= MALLOC_MAGIC) { /* Chunk allocation */ | 912 | } else if (*mp >= MALLOC_MAGIC) { /* Chunk allocation */ |
@@ -914,7 +914,7 @@ irealloc(ptr, size) | |||
914 | /* Check the pointer for sane values */ | 914 | /* Check the pointer for sane values */ |
915 | if ((u_long)ptr & ((1UL<<((*mp)->shift))-1)) { | 915 | if ((u_long)ptr & ((1UL<<((*mp)->shift))-1)) { |
916 | wrtwarning("modified (chunk-) pointer.\n"); | 916 | wrtwarning("modified (chunk-) pointer.\n"); |
917 | return 0; | 917 | return (NULL); |
918 | } | 918 | } |
919 | 919 | ||
920 | /* Find the chunk index in the page */ | 920 | /* Find the chunk index in the page */ |
@@ -923,7 +923,7 @@ irealloc(ptr, size) | |||
923 | /* Verify that it isn't a free chunk already */ | 923 | /* Verify that it isn't a free chunk already */ |
924 | if ((*mp)->bits[i/MALLOC_BITS] & (1UL<<(i%MALLOC_BITS))) { | 924 | if ((*mp)->bits[i/MALLOC_BITS] & (1UL<<(i%MALLOC_BITS))) { |
925 | wrtwarning("chunk is already free.\n"); | 925 | wrtwarning("chunk is already free.\n"); |
926 | return 0; | 926 | return (NULL); |
927 | } | 927 | } |
928 | 928 | ||
929 | osize = (*mp)->size; | 929 | osize = (*mp)->size; |
@@ -934,17 +934,17 @@ irealloc(ptr, size) | |||
934 | osize == malloc_minsize)) { /* ..(if there is one) */ | 934 | osize == malloc_minsize)) { /* ..(if there is one) */ |
935 | if (malloc_junk) | 935 | if (malloc_junk) |
936 | memset((char *)ptr + size, SOME_JUNK, osize-size); | 936 | memset((char *)ptr + size, SOME_JUNK, osize-size); |
937 | return ptr; /* ..don't do anything else. */ | 937 | return (ptr); /* ..don't do anything else. */ |
938 | } | 938 | } |
939 | 939 | ||
940 | } else { | 940 | } else { |
941 | wrtwarning("pointer to wrong page.\n"); | 941 | wrtwarning("pointer to wrong page.\n"); |
942 | return 0; | 942 | return (NULL); |
943 | } | 943 | } |
944 | 944 | ||
945 | p = imalloc(size); | 945 | p = imalloc(size); |
946 | 946 | ||
947 | if (p) { | 947 | if (p != NULL) { |
948 | /* copy the lesser of the two sizes, and free the old one */ | 948 | /* copy the lesser of the two sizes, and free the old one */ |
949 | /* Don't move from/to 0 sized region !!! */ | 949 | /* Don't move from/to 0 sized region !!! */ |
950 | if (osize != 0 && size != 0) { | 950 | if (osize != 0 && size != 0) { |
@@ -955,7 +955,7 @@ irealloc(ptr, size) | |||
955 | } | 955 | } |
956 | ifree(ptr); | 956 | ifree(ptr); |
957 | } | 957 | } |
958 | return p; | 958 | return (p); |
959 | } | 959 | } |
960 | 960 | ||
961 | /* | 961 | /* |
@@ -969,7 +969,7 @@ free_pages(ptr, index, info) | |||
969 | struct pginfo *info; | 969 | struct pginfo *info; |
970 | { | 970 | { |
971 | int i; | 971 | int i; |
972 | struct pgfree *pf, *pt=0; | 972 | struct pgfree *pf, *pt=NULL; |
973 | u_long l; | 973 | u_long l; |
974 | void *tail; | 974 | void *tail; |
975 | 975 | ||
@@ -1006,26 +1006,27 @@ free_pages(ptr, index, info) | |||
1006 | tail = (char *)ptr+l; | 1006 | tail = (char *)ptr+l; |
1007 | 1007 | ||
1008 | /* add to free-list */ | 1008 | /* add to free-list */ |
1009 | if (!px) | 1009 | if (px == NULL) |
1010 | px = imalloc(sizeof *px); /* This cannot fail... */ | 1010 | px = imalloc(sizeof *px); /* This cannot fail... */ |
1011 | px->page = ptr; | 1011 | px->page = ptr; |
1012 | px->end = tail; | 1012 | px->end = tail; |
1013 | px->size = l; | 1013 | px->size = l; |
1014 | if (!free_list.next) { | 1014 | |
1015 | if (free_list.next == NULL) { | ||
1015 | 1016 | ||
1016 | /* Nothing on free list, put this at head */ | 1017 | /* Nothing on free list, put this at head */ |
1017 | px->next = free_list.next; | 1018 | px->next = free_list.next; |
1018 | px->prev = &free_list; | 1019 | px->prev = &free_list; |
1019 | free_list.next = px; | 1020 | free_list.next = px; |
1020 | pf = px; | 1021 | pf = px; |
1021 | px = 0; | 1022 | px = NULL; |
1022 | 1023 | ||
1023 | } else { | 1024 | } else { |
1024 | 1025 | ||
1025 | /* Find the right spot, leave pf pointing to the modified entry. */ | 1026 | /* Find the right spot, leave pf pointing to the modified entry. */ |
1026 | tail = (char *)ptr+l; | ||
1027 | 1027 | ||
1028 | for(pf = free_list.next; pf->end < ptr && pf->next; pf = pf->next) | 1028 | for(pf = free_list.next; pf->end < ptr && pf->next != NULL; |
1029 | pf = pf->next) | ||
1029 | ; /* Race ahead here */ | 1030 | ; /* Race ahead here */ |
1030 | 1031 | ||
1031 | if (pf->page > tail) { | 1032 | if (pf->page > tail) { |
@@ -1035,38 +1036,38 @@ free_pages(ptr, index, info) | |||
1035 | pf->prev = px; | 1036 | pf->prev = px; |
1036 | px->prev->next = px; | 1037 | px->prev->next = px; |
1037 | pf = px; | 1038 | pf = px; |
1038 | px = 0; | 1039 | px = NULL; |
1039 | } else if (pf->end == ptr ) { | 1040 | } else if (pf->end == ptr ) { |
1040 | /* Append to the previous entry */ | 1041 | /* Append to the previous entry */ |
1041 | pf->end = (char *)pf->end + l; | 1042 | pf->end = (char *)pf->end + l; |
1042 | pf->size += l; | 1043 | pf->size += l; |
1043 | if (pf->next && pf->end == pf->next->page ) { | 1044 | if (pf->next != NULL && pf->end == pf->next->page ) { |
1044 | /* And collapse the next too. */ | 1045 | /* And collapse the next too. */ |
1045 | pt = pf->next; | 1046 | pt = pf->next; |
1046 | pf->end = pt->end; | 1047 | pf->end = pt->end; |
1047 | pf->size += pt->size; | 1048 | pf->size += pt->size; |
1048 | pf->next = pt->next; | 1049 | pf->next = pt->next; |
1049 | if (pf->next) | 1050 | if (pf->next != NULL) |
1050 | pf->next->prev = pf; | 1051 | pf->next->prev = pf; |
1051 | } | 1052 | } |
1052 | } else if (pf->page == tail) { | 1053 | } else if (pf->page == tail) { |
1053 | /* Prepend to entry */ | 1054 | /* Prepend to entry */ |
1054 | pf->size += l; | 1055 | pf->size += l; |
1055 | pf->page = ptr; | 1056 | pf->page = ptr; |
1056 | } else if (!pf->next) { | 1057 | } else if (pf->next == NULL) { |
1057 | /* Append at tail of chain */ | 1058 | /* Append at tail of chain */ |
1058 | px->next = 0; | 1059 | px->next = NULL; |
1059 | px->prev = pf; | 1060 | px->prev = pf; |
1060 | pf->next = px; | 1061 | pf->next = px; |
1061 | pf = px; | 1062 | pf = px; |
1062 | px = 0; | 1063 | px = NULL; |
1063 | } else { | 1064 | } else { |
1064 | wrterror("freelist is destroyed.\n"); | 1065 | wrterror("freelist is destroyed.\n"); |
1065 | } | 1066 | } |
1066 | } | 1067 | } |
1067 | 1068 | ||
1068 | /* Return something to OS ? */ | 1069 | /* Return something to OS ? */ |
1069 | if (!pf->next && /* If we're the last one, */ | 1070 | if (pf->next == NULL && /* If we're the last one, */ |
1070 | pf->size > malloc_cache && /* ..and the cache is full, */ | 1071 | pf->size > malloc_cache && /* ..and the cache is full, */ |
1071 | pf->end == malloc_brk && /* ..and none behind us, */ | 1072 | pf->end == malloc_brk && /* ..and none behind us, */ |
1072 | malloc_brk == sbrk(0)) { /* ..and it's OK to do... */ | 1073 | malloc_brk == sbrk(0)) { /* ..and it's OK to do... */ |
@@ -1090,7 +1091,7 @@ free_pages(ptr, index, info) | |||
1090 | 1091 | ||
1091 | /* XXX: We could realloc/shrink the pagedir here I guess. */ | 1092 | /* XXX: We could realloc/shrink the pagedir here I guess. */ |
1092 | } | 1093 | } |
1093 | if (pt) | 1094 | if (pt != NULL) |
1094 | ifree(pt); | 1095 | ifree(pt); |
1095 | } | 1096 | } |
1096 | 1097 | ||
@@ -1181,7 +1182,7 @@ ifree(ptr) | |||
1181 | int index; | 1182 | int index; |
1182 | 1183 | ||
1183 | /* This is legal */ | 1184 | /* This is legal */ |
1184 | if (!ptr) | 1185 | if (ptr == NULL) |
1185 | return; | 1186 | return; |
1186 | 1187 | ||
1187 | if (!malloc_started) { | 1188 | if (!malloc_started) { |
@@ -1231,13 +1232,13 @@ malloc(size_t size) | |||
1231 | wrtwarning("recursive call.\n"); | 1232 | wrtwarning("recursive call.\n"); |
1232 | malloc_active--; | 1233 | malloc_active--; |
1233 | _MALLOC_UNLOCK(); | 1234 | _MALLOC_UNLOCK(); |
1234 | return (0); | 1235 | return (NULL); |
1235 | } | 1236 | } |
1236 | r = imalloc(size); | 1237 | r = imalloc(size); |
1237 | UTRACE(0, size, r); | 1238 | UTRACE(0, size, r); |
1238 | malloc_active--; | 1239 | malloc_active--; |
1239 | _MALLOC_UNLOCK(); | 1240 | _MALLOC_UNLOCK(); |
1240 | if (malloc_xmalloc && !r) | 1241 | if (malloc_xmalloc && r == NULL) |
1241 | wrterror("out of memory.\n"); | 1242 | wrterror("out of memory.\n"); |
1242 | return (r); | 1243 | return (r); |
1243 | } | 1244 | } |
@@ -1271,9 +1272,9 @@ realloc(void *ptr, size_t size) | |||
1271 | wrtwarning("recursive call.\n"); | 1272 | wrtwarning("recursive call.\n"); |
1272 | malloc_active--; | 1273 | malloc_active--; |
1273 | _MALLOC_UNLOCK(); | 1274 | _MALLOC_UNLOCK(); |
1274 | return (0); | 1275 | return (NULL); |
1275 | } | 1276 | } |
1276 | if (!ptr) { | 1277 | if (ptr == NULL) { |
1277 | r = imalloc(size); | 1278 | r = imalloc(size); |
1278 | } else { | 1279 | } else { |
1279 | r = irealloc(ptr, size); | 1280 | r = irealloc(ptr, size); |
@@ -1281,7 +1282,7 @@ realloc(void *ptr, size_t size) | |||
1281 | UTRACE(ptr, size, r); | 1282 | UTRACE(ptr, size, r); |
1282 | malloc_active--; | 1283 | malloc_active--; |
1283 | _MALLOC_UNLOCK(); | 1284 | _MALLOC_UNLOCK(); |
1284 | if (malloc_xmalloc && !r) | 1285 | if (malloc_xmalloc && r == NULL) |
1285 | wrterror("out of memory.\n"); | 1286 | wrterror("out of memory.\n"); |
1286 | return (r); | 1287 | return (r); |
1287 | } | 1288 | } |