home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / next / programm / 6001 < prev    next >
Encoding:
Text File  |  1992-09-07  |  2.5 KB  |  93 lines

  1. Path: sparky!uunet!sun-barr!sh.wide!wnoc-tyo-news!lkbreth!sgtp!shin
  2. From: shin@sgtp.apple.juice.or.jp (Sugou Shinichirou)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: Re: malloc_error
  5. Message-ID: <SHIN.92Sep5171016@sgtp.sgtp.apple.juice.or.jp>
  6. Date: 5 Sep 92 08:10:16 GMT
  7. References: <SHIN.92Aug29190422@sgtp.sgtp.apple.juice.or.jp>
  8.     <1992Aug31.172521.847@svcdudes.com>
  9. Sender: shin@sgtp.apple.juice.or.jp
  10. Distribution: comp
  11. Organization: SG Total Planning, Japan
  12. Lines: 78
  13. In-reply-to: moose@svcdudes.com's message of 1 Sep 92 02:25:21 JST
  14.  
  15. In article <1992Aug31.172521.847@svcdudes.com> moose@svcdudes.com writes:
  16.    > I don't know the way how to use 'malloc_error' function. Please refer to
  17.    > the UNIX manual 'malloc_error' about the detailed information.
  18.    > 
  19.    > Suppose I want to execute myMallocErr() instead of the default routine
  20.    > whenever memory allocation error happens.
  21.    > 
  22.    > void myMallocErr(int code)
  23.    > {
  24.    >         printf("error");
  25.    >         abort();
  26.    > }
  27.    > 
  28.    > (2) Link program with  '-lMallocDebug'. For example: If you are using IB,
  29.    >     define the following line within Makefile.preamble, and 'make debug'
  30.    >     will generate the malloc-check-routine active code.
  31.    > 
  32.    >     OTHER_DEBUG_LIBS = -lMallocDebug
  33.    > 
  34.  
  35.    I believe that linking MallocDebug will override your call you malloc_error.   
  36.    Try this without linking in MallocDebug
  37.  
  38. I thank you for your suggestion.
  39.  
  40. I tried, but it seems not to be invoked still yet. The following is a very
  41. simple test program.
  42.  
  43. ------tmp1.c----------------------------------------
  44. #import <stdlib.h>
  45. #import <stdio.h>
  46.  
  47. void myMallocErr(int code)
  48. {
  49.    fprintf(stderr, "malloc error");
  50. }
  51.  
  52. main()
  53. {
  54.    char *p;
  55.  
  56.    malloc_debug(32);
  57.    malloc_error(myMallocErr);
  58.  
  59.    p = malloc(10);
  60.    free(p);
  61.    free(p);    // should be error!!
  62.    exit(0);
  63. }
  64. ---------------------------------------------------
  65. When I compile it without '-lMallocDebug':
  66.  
  67.         %shell cc -g tmp1.c -o tmp1
  68.  
  69. No malloc error is detected. Even if I comment out 'malloc_error()'
  70. sentence, again, no malloc error is detected.(--> malloc check routine deactiveted?)
  71.  
  72. When I compile with '-lMallocDebug':
  73.  
  74.         %shell cc -g tmp1.c -o tmp1 -lMallocDebug
  75.  
  76. the default error-message-routine is called. Even if I comment out
  77. 'malloc_error()' sentence, the result is the same.
  78.  
  79. Therefore, I think '-lMallocDebug' library is necessary when I make malloc
  80. routine active.
  81.  
  82. But still I don't know the way how to change error-message-routine.
  83.  
  84. Any suggestion is appreciated.
  85.  
  86. --
  87. Shin'ichirou Sugou
  88.  
  89. shin@apple.juice.or.jp (NeXTmail acceptable)
  90.  
  91.  
  92.                    
  93.