From b5692654225446ad2c1e43d9b2d45fb1d97de61c Mon Sep 17 00:00:00 2001 From: yang1946 Date: Sat, 25 May 2024 14:04:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=AD=BE=E5=90=8D=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yang1946 --- services/key_enable/utils/src/devices_security.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/key_enable/utils/src/devices_security.cpp b/services/key_enable/utils/src/devices_security.cpp index 99bfe85..7b1195b 100644 --- a/services/key_enable/utils/src/devices_security.cpp +++ b/services/key_enable/utils/src/devices_security.cpp @@ -27,9 +27,9 @@ constexpr int32_t VALUE_MAX_LEN = 64; constexpr int32_t CMDLINE_MAX_BUF_LEN = 4096; -const std::string OEM_MODE = "const.boot.oemmode"; -const std::string OEM_MODE_RD = "rd"; -const std::string EFUSE_STATE_FILE = "/proc/cmdline"; +static const std::string OEM_MODE = "const.boot.oemmode"; +static const std::string OEM_MODE_RD = "rd"; +static const std::string EFUSE_STATE_FILE = "/proc/cmdline"; using namespace OHOS::Security::CodeSign; @@ -44,6 +44,7 @@ int32_t GetEfuseStatus() char *buf = static_cast(malloc(CMDLINE_MAX_BUF_LEN)); if (buf == nullptr) { LOG_ERROR(LABEL, "alloc read buffer failed"); + (void) close(fd); return DEVICE_MODE_ERROR; } (void)memset_s(buf, CMDLINE_MAX_BUF_LEN, 0, CMDLINE_MAX_BUF_LEN); @@ -53,6 +54,8 @@ int32_t GetEfuseStatus() (void) close(fd); if (ret < 0) { LOG_ERROR(LABEL, "read %{public}s failed, %{public}s", EFUSE_STATE_FILE.c_str(), strerror(errno)); + free(buf); + buf = nullptr; return deviceMode; } -- Gitee