Index: lib/profile/GCDAProfiling.c =================================================================== --- lib/profile/GCDAProfiling.c +++ lib/profile/GCDAProfiling.c @@ -263,8 +263,9 @@ * same GCDA. This can fail if the filesystem doesn't support it, but in that * case we'll just carry on with the old racy behaviour and hope for the best. */ - flock(fd, LOCK_EX); - output_file = fdopen(fd, mode); + close(fd); + output_file = fopen(filename, mode); + flock(fileno(output_file), LOCK_EX); /* Initialize the write buffer. */ write_buffer = NULL; @@ -462,7 +463,7 @@ unmap_file(); } - flock(fd, LOCK_UN); + flock(fileno(output_file), LOCK_UN); fclose(output_file); output_file = NULL; write_buffer = NULL;