修复专用机接口的内存泄露问题

This commit is contained in:
wangjingwen 2022-04-12 15:13:12 +08:00
parent 5e12794eed
commit fc3b66a302
1 changed files with 17 additions and 11 deletions

View File

@ -11,8 +11,8 @@ static char* get_val_from_file(FILE *fp, const char *key)
{
if (! fp)
return NULL;
char *val;
char buf[1024];
char *val = NULL;
char buf[1024] = {0};
while (fgets(buf, 1024, fp))
{
if (strncmp(buf, key, strlen(key)) == 0)
@ -368,17 +368,23 @@ char* kdk_system_get_currentUser()
bool kdk_system_is_zyj(void)
{
char *project_codename = NULL;
bool bool_value = FALSE;
FILE *fp = fopen("/etc/os-release", "r");
if (!fp)
return FALSE;
return bool_value;
project_codename = get_val_from_file(fp, "PROJECT_CODENAME");
if (strstr(project_codename, "zyj") ||strstr(project_codename, "ZYJ") )
{
return TRUE;
}
fclose(fp);
return FALSE;
if (project_codename && (strstr(project_codename, "zyj") || strstr(project_codename, "ZYJ")) )
bool_value = TRUE;
else
bool_value = FALSE;
exit:
fclose(fp);
if(project_codename)
free(project_codename);
return bool_value;
}