Sourceware Bugzilla – Attachment 5676 Details for
Bug 12683
Race conditions in pthread cancellation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
Demonstration of file descriptor leak due to problem 1
cancel_race.c (text/x-csrc), 894 bytes, created by
Rich Felker
on 2011-04-18 22:28:16 UTC
(
hide
)
Description:
Demonstration of file descriptor leak due to problem 1
Filename:
MIME Type:
Creator:
Rich Felker
Created:
2011-04-18 22:28:16 UTC
Size:
894 bytes
patch
obsolete
>#define _POSIX_C_SOURCE 200809L >#include <pthread.h> >#include <fcntl.h> >#include <sys/stat.h> >#include <time.h> >#include <stdio.h> > >void *writeopener(void *arg) >{ > int fd; > for (;;) { > fd = open(arg, O_WRONLY); > close(fd); > } >} > >void *leaker(void *arg) >{ > int fd = open(arg, O_RDONLY); > pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); > close(fd); > return 0; >} > > >#define ITER_COUNT 10000 > >int main() >{ > pthread_t td, bg; > struct stat st; > char tmp[] = "/tmp/cancel_race_XXXXXX"; > int i, leaks=0; > > mktemp(tmp); > mkfifo(tmp, 0600); > srand(1); > pthread_create(&bg, 0, writeopener, tmp); > for (i=0; i<ITER_COUNT; i++) { > pthread_create(&td, 0, leaker, tmp); > nanosleep((&(struct timespec){ .tv_nsec=rand()%100000 }), 0); > pthread_cancel(td); > pthread_join(td, 0); > } > unlink(tmp); > for (i=3; i<1024; i++) { > if (!fstat(i, &st)) leaks++, printf("leaked fd %d\n", i); > } > return !!leaks; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 12683
: 5676 |
5677