提交 cad4cb80 编写于 作者: X xlei1030

增加FullName校验和失败时内存释放

Signed-off-by: Nxlei1030 <xionglei6@huawei.com>
上级 9e6b6218
......@@ -242,19 +242,23 @@ static const char *BuildOSFullName(void)
{
const char release[] = "Release";
const char *releaseType = GetOsReleaseType();
const char *fillname = GetFullName_();
if ((releaseType != NULL) && (strncmp(releaseType, release, sizeof(release) - 1) != 0)) {
const char *fullName = GetFullName_();
if (fullName == NULL || releaseType == NULL) {
return NULL;
}
if (strncmp(releaseType, release, sizeof(release) - 1) != 0) {
char *value = calloc(1, OS_FULL_NAME_LEN);
if (value == NULL) {
return NULL;
}
int length = sprintf_s(value, OS_FULL_NAME_LEN, "%s(%s)", fillname, releaseType);
int length = sprintf_s(value, OS_FULL_NAME_LEN, "%s(%s)", fullName, releaseType);
if (length < 0) {
free(value);
return NULL;
}
return value;
}
return strdup(fillname);
return strdup(fullName);
}
const char *GetOSFullName(void)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册