Skip to content

Bug: Crash after forked child exits #1524

Description

@haael

Contact Details

haael@interia.pl

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

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 ?? ()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    high severityUsed to report high severity bugs (Malfunctioning hinder important workflow)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions