]> www.infradead.org Git - mtd-utils.git/commitdiff
jittertest: fix error check for open system call
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Sun, 10 Nov 2019 14:12:58 +0000 (15:12 +0100)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Sun, 10 Nov 2019 14:30:04 +0000 (15:30 +0100)
The value 0 is a valid file descriptor. The existing error handling
would not only treat that as an error, but subsequently leak the
file descriptor in the error handling path.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
tests/jittertest/JitterTest.c

index e1099959d0f697426b36f5151f60d9e9d43fbd9f..797035b1ab628f4359a6796fa0fc1aa4c58ee8e9 100644 (file)
@@ -462,14 +462,14 @@ static void doGrabKProfile(int jitterusec, char *fileName)
 
     (void)jitterusec;
 
-    if((fdSnapshot = open(fileName, O_WRONLY | O_CREAT, S_IRWXU)) <= 0)
+    if((fdSnapshot = open(fileName, O_WRONLY | O_CREAT, S_IRWXU)) < 0)
     {
         fprintf(stderr, "Could not open file %s.\n", fileName);
         perror("Error:");
         return;
     }
 
-    if((fdProfile = open("/proc/profile", O_RDWR)) <= 0)
+    if((fdProfile = open("/proc/profile", O_RDWR)) < 0)
     {
         fprintf(stderr, "Could not open file /proc/profile. Make sure you booted with profile=2\n");
         close(fdSnapshot);
@@ -509,7 +509,7 @@ static void clearProfileBuf(void){
   char readBuf[10];
 
 
-  if((fdProfile = open("/proc/profile", O_RDWR)) <= 0)
+  if((fdProfile = open("/proc/profile", O_RDWR)) < 0)
     {
       fprintf(stderr, "Could not open file /proc/profile. Make sure you booted with profile=2\n");
       return;