diff options
| author | Miles Bader | 2005-01-02 09:13:19 +0000 |
|---|---|---|
| committer | Miles Bader | 2005-01-02 09:13:19 +0000 |
| commit | f1d34bcacd8dd9d730000f1fe8827559e1c89683 (patch) | |
| tree | 9fd51451ad8b295052bf912ed49c73d7b4d1c9a3 /src/alloc.c | |
| parent | 0e9dd01c1246ee481efa3e71462d9db952072176 (diff) | |
| parent | 553fd77e2511cdc4d1b45933f237c724ee72c3b9 (diff) | |
| download | emacs-f1d34bcacd8dd9d730000f1fe8827559e1c89683.tar.gz emacs-f1d34bcacd8dd9d730000f1fe8827559e1c89683.zip | |
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-81
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-748
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-749
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-750
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-751
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-753
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-754
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-755
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-757
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-78
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-79
- miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-80
Update from CVS
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-81
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2004/gnus--rel--5.10--patch-82
Update from CVS
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/alloc.c b/src/alloc.c index 9dd5e1abc05..6c393e9213b 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -601,6 +601,27 @@ static char xmalloc_overrun_check_trailer[XMALLOC_OVERRUN_CHECK_SIZE] = | |||
| 601 | ((unsigned)(ptr[-4]) << 24)) | 601 | ((unsigned)(ptr[-4]) << 24)) |
| 602 | 602 | ||
| 603 | 603 | ||
| 604 | /* The call depth in overrun_check functions. For example, this might happen: | ||
| 605 | xmalloc() | ||
| 606 | overrun_check_malloc() | ||
| 607 | -> malloc -> (via hook)_-> emacs_blocked_malloc | ||
| 608 | -> overrun_check_malloc | ||
| 609 | call malloc (hooks are NULL, so real malloc is called). | ||
| 610 | malloc returns 10000. | ||
| 611 | add overhead, return 10016. | ||
| 612 | <- (back in overrun_check_malloc) | ||
| 613 | add overhead again, return 10032 | ||
| 614 | xmalloc returns 10032. | ||
| 615 | |||
| 616 | (time passes). | ||
| 617 | |||
| 618 | xfree(10032) | ||
| 619 | overrun_check_free(10032) | ||
| 620 | decrease overhed | ||
| 621 | free(10016) <- crash, because 10000 is the original pointer. */ | ||
| 622 | |||
| 623 | static int check_depth; | ||
| 624 | |||
| 604 | /* Like malloc, but wraps allocated block with header and trailer. */ | 625 | /* Like malloc, but wraps allocated block with header and trailer. */ |
| 605 | 626 | ||
| 606 | POINTER_TYPE * | 627 | POINTER_TYPE * |
| @@ -608,15 +629,17 @@ overrun_check_malloc (size) | |||
| 608 | size_t size; | 629 | size_t size; |
| 609 | { | 630 | { |
| 610 | register unsigned char *val; | 631 | register unsigned char *val; |
| 632 | size_t overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_SIZE*2 : 0; | ||
| 611 | 633 | ||
| 612 | val = (unsigned char *) malloc (size + XMALLOC_OVERRUN_CHECK_SIZE*2); | 634 | val = (unsigned char *) malloc (size + overhead); |
| 613 | if (val) | 635 | if (val && check_depth == 1) |
| 614 | { | 636 | { |
| 615 | bcopy (xmalloc_overrun_check_header, val, XMALLOC_OVERRUN_CHECK_SIZE - 4); | 637 | bcopy (xmalloc_overrun_check_header, val, XMALLOC_OVERRUN_CHECK_SIZE - 4); |
| 616 | val += XMALLOC_OVERRUN_CHECK_SIZE; | 638 | val += XMALLOC_OVERRUN_CHECK_SIZE; |
| 617 | XMALLOC_PUT_SIZE(val, size); | 639 | XMALLOC_PUT_SIZE(val, size); |
| 618 | bcopy (xmalloc_overrun_check_trailer, val + size, XMALLOC_OVERRUN_CHECK_SIZE); | 640 | bcopy (xmalloc_overrun_check_trailer, val + size, XMALLOC_OVERRUN_CHECK_SIZE); |
| 619 | } | 641 | } |
| 642 | --check_depth; | ||
| 620 | return (POINTER_TYPE *)val; | 643 | return (POINTER_TYPE *)val; |
| 621 | } | 644 | } |
| 622 | 645 | ||
| @@ -630,8 +653,10 @@ overrun_check_realloc (block, size) | |||
| 630 | size_t size; | 653 | size_t size; |
| 631 | { | 654 | { |
| 632 | register unsigned char *val = (unsigned char *)block; | 655 | register unsigned char *val = (unsigned char *)block; |
| 656 | size_t overhead = ++check_depth == 1 ? XMALLOC_OVERRUN_CHECK_SIZE*2 : 0; | ||
| 633 | 657 | ||
| 634 | if (val | 658 | if (val |
| 659 | && check_depth == 1 | ||
| 635 | && bcmp (xmalloc_overrun_check_header, | 660 | && bcmp (xmalloc_overrun_check_header, |
| 636 | val - XMALLOC_OVERRUN_CHECK_SIZE, | 661 | val - XMALLOC_OVERRUN_CHECK_SIZE, |
| 637 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) | 662 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) |
| @@ -646,15 +671,16 @@ overrun_check_realloc (block, size) | |||
| 646 | bzero (val, XMALLOC_OVERRUN_CHECK_SIZE); | 671 | bzero (val, XMALLOC_OVERRUN_CHECK_SIZE); |
| 647 | } | 672 | } |
| 648 | 673 | ||
| 649 | val = (unsigned char *) realloc ((POINTER_TYPE *)val, size + XMALLOC_OVERRUN_CHECK_SIZE*2); | 674 | val = (unsigned char *) realloc ((POINTER_TYPE *)val, size + overhead); |
| 650 | 675 | ||
| 651 | if (val) | 676 | if (val && check_depth == 1) |
| 652 | { | 677 | { |
| 653 | bcopy (xmalloc_overrun_check_header, val, XMALLOC_OVERRUN_CHECK_SIZE - 4); | 678 | bcopy (xmalloc_overrun_check_header, val, XMALLOC_OVERRUN_CHECK_SIZE - 4); |
| 654 | val += XMALLOC_OVERRUN_CHECK_SIZE; | 679 | val += XMALLOC_OVERRUN_CHECK_SIZE; |
| 655 | XMALLOC_PUT_SIZE(val, size); | 680 | XMALLOC_PUT_SIZE(val, size); |
| 656 | bcopy (xmalloc_overrun_check_trailer, val + size, XMALLOC_OVERRUN_CHECK_SIZE); | 681 | bcopy (xmalloc_overrun_check_trailer, val + size, XMALLOC_OVERRUN_CHECK_SIZE); |
| 657 | } | 682 | } |
| 683 | --check_depth; | ||
| 658 | return (POINTER_TYPE *)val; | 684 | return (POINTER_TYPE *)val; |
| 659 | } | 685 | } |
| 660 | 686 | ||
| @@ -666,7 +692,9 @@ overrun_check_free (block) | |||
| 666 | { | 692 | { |
| 667 | unsigned char *val = (unsigned char *)block; | 693 | unsigned char *val = (unsigned char *)block; |
| 668 | 694 | ||
| 695 | ++check_depth; | ||
| 669 | if (val | 696 | if (val |
| 697 | && check_depth == 1 | ||
| 670 | && bcmp (xmalloc_overrun_check_header, | 698 | && bcmp (xmalloc_overrun_check_header, |
| 671 | val - XMALLOC_OVERRUN_CHECK_SIZE, | 699 | val - XMALLOC_OVERRUN_CHECK_SIZE, |
| 672 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) | 700 | XMALLOC_OVERRUN_CHECK_SIZE - 4) == 0) |
| @@ -682,6 +710,7 @@ overrun_check_free (block) | |||
| 682 | } | 710 | } |
| 683 | 711 | ||
| 684 | free (val); | 712 | free (val); |
| 713 | --check_depth; | ||
| 685 | } | 714 | } |
| 686 | 715 | ||
| 687 | #undef malloc | 716 | #undef malloc |