Bug: Crash after forked child exits

Author: haaelCreated Sep 12, 2026Updated Sep 13, 2026
Labelshigh severity

Contact Details

[email protected]

What happened?

First fork a child. Then return from that child. The parent proces crashes with SIGSEGV.


#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
	pid_t pid;
	printf("enter\n");
	
	pid = vfork();
	
	if(pid < 0)
	{
		printf("error %d\n", pid);
		return 1;
	}
	
	if(pid == 0)
	{
		printf("parent\n");
	}
	else
	{
		printf("child %d\n", pid);
	}
	
	printf("exit\n");
	return 0;
}

What gives?

Version

cosmocc (GCC) 14.1.0

What operating system are you seeing the problem on?

Linux

Relevant log output

bash
The stack trace (from .com.dbg) shows null pointer at the top of the stack.


enter
[Detaching after vfork from child process 11666]
parent
exit
child 11666
exit

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00000000042015de in _start () at libc/crt/crt.S:128


In non-debug binary there are 5 pointers without labels, the top one is null.


Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00000000042015de in ?? ()
#2  0x0000000000000001 in ?? ()
#3  0x00007fffffffe318 in ?? ()
#4  0x0000000000000000 in ?? ()