This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question about flock - potential memory corruption?


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

 * 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");
	int fd2 = open(tmpfilename, O_RDONLY);
	int rc;
	int i;
	rc = flock(fd2, LOCK_EX);
	return 0;
Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]