diff --git a/package/gluon-web/src/template_lmo.c b/package/gluon-web/src/template_lmo.c
index 94ebd1232120e3f63823e6e6dfeeec35806006dd..42881d6e46e2929d1c842de1ad81fad7f1350ad1 100644
--- a/package/gluon-web/src/template_lmo.c
+++ b/package/gluon-web/src/template_lmo.c
@@ -74,10 +74,10 @@ static lmo_archive_t * lmo_open(const char *file)
 
 	lmo_archive_t *ar = NULL;
 
-	if (stat(file, &s) == -1)
+	if ((in = open(file, O_RDONLY|O_CLOEXEC)) == -1)
 		goto err;
 
-	if ((in = open(file, O_RDONLY)) == -1)
+	if (fstat(in, &s) == -1)
 		goto err;
 
 	if ((ar = calloc(1, sizeof(*ar))) != NULL) {
@@ -85,8 +85,6 @@ static lmo_archive_t * lmo_open(const char *file)
 		ar->fd     = in;
 		ar->size = s.st_size;
 
-		fcntl(ar->fd, F_SETFD, fcntl(ar->fd, F_GETFD) | FD_CLOEXEC);
-
 		if ((ar->mmap = mmap(NULL, ar->size, PROT_READ, MAP_SHARED, ar->fd, 0)) == MAP_FAILED)
 			goto err;
 
diff --git a/package/gluon-web/src/template_parser.c b/package/gluon-web/src/template_parser.c
index 4f3ad15f796eaa6a0d928447a5b4b3a3c3bb3eb8..2c5379f7861e43f0234a8fce09649038ff443854 100644
--- a/package/gluon-web/src/template_parser.c
+++ b/package/gluon-web/src/template_parser.c
@@ -45,10 +45,10 @@ struct template_parser * template_open(const char *file)
 	parser->fd = -1;
 	parser->file = file;
 
-	if (stat(file, &s))
+	if ((parser->fd = open(file, O_RDONLY|O_CLOEXEC)) < 0)
 		goto err;
 
-	if ((parser->fd = open(file, O_RDONLY)) < 0)
+	if (fstat(parser->fd, &s))
 		goto err;
 
 	parser->size = s.st_size;