This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Question about flock - potential memory corruption?
- From: Qian Hong <fracting at gmail dot com>
- To: cygwin <cygwin at cygwin dot com>
- Date: Tue, 8 Sep 2015 02:45:20 +0800
- Subject: Re: Question about flock - potential memory corruption?
- Authentication-results: sourceware.org; auth=none
- References: <CALd+sZRo_Nyv=adF5DeeHiShJsxGD+KUPqkDMKb3q47a2Nm=8Q at mail dot gmail dot com> <CALd+sZSUAt6_fdHkgdKqefz1Wv-ijShSo82qJKUcCkZH9v5KzA at mail dot gmail dot com>
- Reply-to: fracting at gmail dot com
Hi,
Attach is the simple test case I use to reproduce the valgrind warning
and random failures.
Compile the test case in Cygwin with below command line:
$ gcc -g -O0 flock.c -o flock.exe
Thanks!
/***********************************************************************
* This is a STC that causes the following error on my test machine:
* NtCreateEvent(lock): 0xC0000035
*
* It tries to use flock() for file locking. It creates a temporary
* file, the uses fork to spawn a number of children. Each child opens
* the file, then repeatedly uses flock to lock and unlock it.
*
* This test was extracted from the APR test suite.
*
* Compile: gcc -Wall -o stc-flock-fork stc-flock-fork.c
***********************************************************************/
#include <sys/types.h>
#include <sys/file.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#define MAX_ITER 2000
#define CHILDREN 6
/* A temporary file used for flock. */
char tmpfilename[] = "/tmp/flocktstXXXXXX";
int main(int argc, const char * const * argv, const char * const *env)
{
int fd;
/* Create the temporary file. */
fd = mkstemp(tmpfilename);
if (fd < 0) {
perror("open failed");
exit(1);
}
close(fd);
int fd2 = open(tmpfilename, O_RDONLY);
int rc;
int i;
rc = flock(fd2, LOCK_EX);
return 0;
}
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple