X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tests%2Ftest-lockfile.c;h=f0f4b010a112852c673900f61f15d851c940bb5b;hb=2da0385d1f57fe00977d2e58022b3f9a6604192e;hp=31e13a72c42d7006543dbb1d1b0cc3a9e8d7b3fc;hpb=58fda1dab104041fc693032475ec4662c1a52849;p=openvswitch diff --git a/tests/test-lockfile.c b/tests/test-lockfile.c index 31e13a72..f0f4b010 100644 --- a/tests/test-lockfile.c +++ b/tests/test-lockfile.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009 Nicira Networks. + * Copyright (c) 2009, 2010 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -100,10 +100,15 @@ do_fork(void) static void run_lock_blocks_other_process(void) { - struct lockfile *lockfile; + /* Making this static prevents a memory leak warning from valgrind for the + * parent process, which cannot easily unlock (and free) 'lockfile' because + * it can only do so after the child has exited, and it's the caller of + * this function that does the wait() call. */ + static struct lockfile *lockfile; assert(lockfile_lock("file", 0, &lockfile) == 0); if (do_fork() == CHILD) { + lockfile_unlock(lockfile); assert(lockfile_lock("file", 0, &lockfile) == EAGAIN); exit(11); } @@ -144,6 +149,7 @@ run_lock_timeout_gets_the_lock(void) assert(lockfile_lock("file", 0, &lockfile) == 0); if (do_fork() == CHILD) { + lockfile_unlock(lockfile); assert(lockfile_lock("file", TIME_UPDATE_INTERVAL * 3, &lockfile) == 0); exit(11); @@ -164,6 +170,7 @@ run_lock_timeout_runs_out(void) assert(lockfile_lock("file", 0, &lockfile) == 0); if (do_fork() == CHILD) { + lockfile_unlock(lockfile); assert(lockfile_lock("file", TIME_UPDATE_INTERVAL, &lockfile) == ETIMEDOUT); exit(11);