From acid@unix-server.local.gem.pl  Thu Aug 23 04:49:53 2001
Return-Path: <acid@unix-server.local.gem.pl>
Received: from unix-server.local.gem.pl (gateway.g-em.pl [212.45.233.230])
	by hub.freebsd.org (Postfix) with ESMTP id 1BF2E37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 23 Aug 2001 04:49:45 -0700 (PDT)
	(envelope-from acid@unix-server.local.gem.pl)
Received: (from acid@localhost)
	by unix-server.local.gem.pl (8.11.5/8.11.5) id f7NBnTu98952;
	Thu, 23 Aug 2001 13:49:29 +0200 (CEST)
	(envelope-from acid)
Message-Id: <200108231149.f7NBnTu98952@unix-server.local.gem.pl>
Date: Thu, 23 Aug 2001 13:49:29 +0200 (CEST)
From: Jakub Kruszona-Zawadzki <acid@gem.pl>
Reply-To: Jakub Kruszona-Zawadzki <acid@gem.pl>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: error in libc (simultanous call to malloc or free and printf causes Segmentation Fault)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         29987
>Category:       misc
>Synopsis:       error in libc (simultanous call to malloc or free and printf causes Segmentation Fault)
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 23 04:50:00 PDT 2001
>Closed-Date:    Thu Aug 23 14:50:00 PDT 2001
>Last-Modified:  Thu Aug 23 14:50:30 PDT 2001
>Originator:     Jakub Kruszona-Zawadzki
>Release:        FreeBSD 4.4-PRERELEASE i386
>Organization:
Global eMarketing S.A.
>Environment:

System: FreeBSD unix-server.local.gem.pl 4.4-PRERELEASE FreeBSD 4.4-PRERELEASE #0: Wed Aug 8 11:23:46 CEST 2001 acid@unix-server.local.gem.pl:/usr/obj/usr/src/sys/GEMIUS i386
Machine: Celeron 600

same bug exists on different freebsd versions. We tested FreeBSD 4.1 and FreeBSD 4.3. On both problem exists
(We tested it on Linux too - there is no such problem)

>Description:
	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;
}
/-------------------------------------------------/

>Fix:
>Release-Note:
>Audit-Trail:

From: David Malone <dwmalone@maths.tcd.ie>
To: Jakub Kruszona-Zawadzki <acid@gem.pl>
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: misc/29987: error in libc (simultanous call to malloc or free and printf causes Segmentation Fault)
Date: Thu, 23 Aug 2001 13:19:11 +0100

 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 
State-Changed-By: kris 
State-Changed-When: Thu Aug 23 14:50:00 PDT 2001 
State-Changed-Why:  
That's why these functions are documented as being unsafe 
to use in signal handlers (see sigaction(2)) 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=29987 
>Unformatted:
