home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!sh.wide!wnoc-tyo-news!lkbreth!sgtp!shin
- From: shin@sgtp.apple.juice.or.jp (Sugou Shinichirou)
- Newsgroups: comp.sys.next.programmer
- Subject: Re: malloc_error
- Message-ID: <SHIN.92Sep5171016@sgtp.sgtp.apple.juice.or.jp>
- Date: 5 Sep 92 08:10:16 GMT
- References: <SHIN.92Aug29190422@sgtp.sgtp.apple.juice.or.jp>
- <1992Aug31.172521.847@svcdudes.com>
- Sender: shin@sgtp.apple.juice.or.jp
- Distribution: comp
- Organization: SG Total Planning, Japan
- Lines: 78
- In-reply-to: moose@svcdudes.com's message of 1 Sep 92 02:25:21 JST
-
- In article <1992Aug31.172521.847@svcdudes.com> moose@svcdudes.com writes:
- > I don't know the way how to use 'malloc_error' function. Please refer to
- > the UNIX manual 'malloc_error' about the detailed information.
- >
- > Suppose I want to execute myMallocErr() instead of the default routine
- > whenever memory allocation error happens.
- >
- > void myMallocErr(int code)
- > {
- > printf("error");
- > abort();
- > }
- >
- > (2) Link program with '-lMallocDebug'. For example: If you are using IB,
- > define the following line within Makefile.preamble, and 'make debug'
- > will generate the malloc-check-routine active code.
- >
- > OTHER_DEBUG_LIBS = -lMallocDebug
- >
-
- I believe that linking MallocDebug will override your call you malloc_error.
- Try this without linking in MallocDebug
-
- I thank you for your suggestion.
-
- I tried, but it seems not to be invoked still yet. The following is a very
- simple test program.
-
- ------tmp1.c----------------------------------------
- #import <stdlib.h>
- #import <stdio.h>
-
- void myMallocErr(int code)
- {
- fprintf(stderr, "malloc error");
- }
-
- main()
- {
- char *p;
-
- malloc_debug(32);
- malloc_error(myMallocErr);
-
- p = malloc(10);
- free(p);
- free(p); // should be error!!
- exit(0);
- }
- ---------------------------------------------------
- When I compile it without '-lMallocDebug':
-
- %shell cc -g tmp1.c -o tmp1
-
- No malloc error is detected. Even if I comment out 'malloc_error()'
- sentence, again, no malloc error is detected.(--> malloc check routine deactiveted?)
-
- When I compile with '-lMallocDebug':
-
- %shell cc -g tmp1.c -o tmp1 -lMallocDebug
-
- the default error-message-routine is called. Even if I comment out
- 'malloc_error()' sentence, the result is the same.
-
- Therefore, I think '-lMallocDebug' library is necessary when I make malloc
- routine active.
-
- But still I don't know the way how to change error-message-routine.
-
- Any suggestion is appreciated.
-
- --
- Shin'ichirou Sugou
-
- shin@apple.juice.or.jp (NeXTmail acceptable)
-
-
-
-