nameservice: do not close an fd that is not open
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 23 Oct 2012 11:18:05 +0000 (13:18 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 23 Oct 2012 11:45:14 +0000 (13:45 +0200)
Coverity:
CID 739644 (#1 of 1): Dereference after null check (FORWARD_NULL)At (11): Passing null pointer "add_hosts" to function "fclose(FILE *)", which dereferences it.

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/nameservice/src/nameservice.c

index ed5e050..b467747 100644 (file)
@@ -1092,8 +1092,8 @@ write_hosts_file(void)
       fprintf(hosts, "### contents from '%s' ###\n\n", my_add_hosts);
       while ((c = getc(add_hosts)) != EOF)
         putc(c, hosts);
+      fclose(add_hosts);
     }
-    fclose(add_hosts);
     fprintf(hosts, "\n### olsr names ###\n\n");
   }
   // write own names