comparison common/linuxlockfile.c @ 1333:5d7b1650de1f

Fix pseudo resource leak in case another process is running. Pseudo because this code path leads to an immediate exit.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 15 Oct 2014 15:40:27 +0200
parents 8362e30f7b55
children
comparison
equal deleted inserted replaced
1332:8362e30f7b55 1333:5d7b1650de1f
40 FILE *f = fopen(path, "r"); 40 FILE *f = fopen(path, "r");
41 size_t bytes_read; 41 size_t bytes_read;
42 if (f) 42 if (f)
43 { 43 {
44 bytes_read = fread(oldpid, 1, sizeof(oldpid), f); 44 bytes_read = fread(oldpid, 1, sizeof(oldpid), f);
45 fclose(f);
45 if (bytes_read) 46 if (bytes_read)
46 { 47 {
47 char *oldPath, 48 char *oldPath,
48 *newPath; 49 *newPath;
49 if (bytes_read == sizeof(oldpid)) 50 if (bytes_read == sizeof(oldpid))
65 } 66 }
66 xfree(oldPath); 67 xfree(oldPath);
67 xfree(newPath); 68 xfree(newPath);
68 } 69 }
69 } 70 }
70 fclose(f);
71 } 71 }
72 72
73 ftruncate(fd, 0); 73 ftruncate(fd, 0);
74 pidstrlen = (size_t)snprintf(pidstr, sizeof(pidstr), "%d", 74 pidstrlen = (size_t)snprintf(pidstr, sizeof(pidstr), "%d",
75 getpid()); 75 getpid());

http://wald.intevation.org/projects/trustbridge/