| Summary: | error in libc (simultanous call to malloc or free and printf causes Segmentation Fault) | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Jakub Kruszona-Zawadzki <acid> |
| Component: | misc | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 4.4-PRERELEASE | ||
| Hardware: | Any | ||
| OS: | Any | ||
On Thu, Aug 23, 2001 at 01:49:29PM +0200, Jakub Kruszona-Zawadzki wrote: > same bug exists on different freebsd versions. We tested FreeBSD 4.1 > and FreeBSD 4.3. On both problem exists It is not legal to call printf or malloc from a signal handler. What you are alowd to do in a signal handler depends on if you are writing C according to ANSI, Posix, the Single Unix Specification or some other standard. The sigaction man page has a list of fucntions which you may call from a signal hangler - I think this list is roughly the list given in Posix. > (We tested it on Linux too - there is no such problem) It is more likely the problem was just not detected - FreeBSD's malloc actively tries to spot this problem. David. State Changed From-To: open->closed That's why these functions are documented as being unsafe to use in signal handlers (see sigaction(2)) |
It looks like libc has problems with simultanous calls to some functions How-To-Repeat: Just compile, and run this code: /-------------------------------------------------/ #include <signal.h> #include <stdio.h> void salarm(int sn) { static int s=1; alarm(1); fprintf(stderr,"Test %09d, %lf\n",s,1/((double)s)); s++; } int main() { char *a; int i; signal(SIGALRM,salarm); alarm(1); for (i=0 ; i<1000000 ; i++) { a=(char *)malloc(1000000); if (a==NULL) printf("NULL !!!\n"); free(a); } return 1; } /-------------------------------------------------/