Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Close as soon as possible fd
Baptiste Daroussin committed 4 years ago
commit fba0a6ecd637afbd1d6668c5f0bad9787b764f16
parent 08f33a0
1 file changed +7 -7
modified libpkg/lua.c
@@ -296,18 +296,20 @@ lua_pkg_filecmp(lua_State *L)
		lua_pushinteger(L, 2);
		return (1);
	}
+
	buf1 = mmap(NULL, s1.st_size, PROT_READ, MAP_SHARED, fd1, 0);
+
	close(fd1);
+
	if (buf1 == NULL) {
+
		lua_pushinteger(L, -1);
+
		return (1);
+
	}
	fd2 = openat(rootfd, RELATIVE_PATH(file2), O_RDONLY, DEFFILEMODE);
	if (fd2 == -1) {
		lua_pushinteger(L, 2);
		return (1);
	}

-
	buf1 = mmap(NULL, s1.st_size, PROT_READ, MAP_SHARED, fd1, 0);
-
	if (buf1 == NULL) {
-
		lua_pushinteger(L, -1);
-
		return (1);
-
	}
	buf2 = mmap(NULL, s2.st_size, PROT_READ, MAP_SHARED, fd2, 0);
+
	close(fd2);
	if (buf2 == NULL) {
		lua_pushinteger(L, -1);
		return (1);
@@ -317,8 +319,6 @@ lua_pkg_filecmp(lua_State *L)

	munmap(buf1, s1.st_size);
	munmap(buf2, s2.st_size);
-
	close(fd1);
-
	close(fd2);

	lua_pushinteger(L, ret);
	return (1);