mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 03:09:34 +03:00
Fix coverity defects: CID 147707
coverity scan CID:147707, Type:Double free. Reviewed-by: Richard Laager <rlaager@wiktel.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: cao.xuewen <cao.xuewen@zte.com.cn> Closes #5097
This commit is contained in:
parent
ec009855c4
commit
8047715ab4
@ -72,7 +72,7 @@ smb_retrieve_shares(void)
|
|||||||
{
|
{
|
||||||
int rc = SA_OK;
|
int rc = SA_OK;
|
||||||
char file_path[PATH_MAX], line[512], *token, *key, *value;
|
char file_path[PATH_MAX], line[512], *token, *key, *value;
|
||||||
char *dup_value, *path = NULL, *comment = NULL, *name = NULL;
|
char *dup_value = NULL, *path = NULL, *comment = NULL, *name = NULL;
|
||||||
char *guest_ok = NULL;
|
char *guest_ok = NULL;
|
||||||
DIR *shares_dir;
|
DIR *shares_dir;
|
||||||
FILE *share_file_fp = NULL;
|
FILE *share_file_fp = NULL;
|
||||||
@ -136,12 +136,19 @@ smb_retrieve_shares(void)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(key, "path") == 0)
|
if (strcmp(key, "path") == 0) {
|
||||||
|
free(path);
|
||||||
path = dup_value;
|
path = dup_value;
|
||||||
if (strcmp(key, "comment") == 0)
|
} else if (strcmp(key, "comment") == 0) {
|
||||||
|
free(comment);
|
||||||
comment = dup_value;
|
comment = dup_value;
|
||||||
if (strcmp(key, "guest_ok") == 0)
|
} else if (strcmp(key, "guest_ok") == 0) {
|
||||||
|
free(guest_ok);
|
||||||
guest_ok = dup_value;
|
guest_ok = dup_value;
|
||||||
|
} else
|
||||||
|
free(dup_value);
|
||||||
|
|
||||||
|
dup_value = NULL;
|
||||||
|
|
||||||
if (path == NULL || comment == NULL || guest_ok == NULL)
|
if (path == NULL || comment == NULL || guest_ok == NULL)
|
||||||
continue; /* Incomplete share definition */
|
continue; /* Incomplete share definition */
|
||||||
@ -153,25 +160,24 @@ smb_retrieve_shares(void)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(shares->name, name,
|
(void) strlcpy(shares->name, name,
|
||||||
sizeof (shares->name));
|
sizeof (shares->name));
|
||||||
shares->name [sizeof (shares->name) - 1] = '\0';
|
|
||||||
|
|
||||||
strncpy(shares->path, path,
|
(void) strlcpy(shares->path, path,
|
||||||
sizeof (shares->path));
|
sizeof (shares->path));
|
||||||
shares->path [sizeof (shares->path) - 1] = '\0';
|
|
||||||
|
|
||||||
strncpy(shares->comment, comment,
|
(void) strlcpy(shares->comment, comment,
|
||||||
sizeof (shares->comment));
|
sizeof (shares->comment));
|
||||||
shares->comment[sizeof (shares->comment)-1] =
|
|
||||||
'\0';
|
|
||||||
|
|
||||||
shares->guest_ok = atoi(guest_ok);
|
shares->guest_ok = atoi(guest_ok);
|
||||||
|
|
||||||
shares->next = new_shares;
|
shares->next = new_shares;
|
||||||
new_shares = shares;
|
new_shares = shares;
|
||||||
|
|
||||||
name = NULL;
|
free(path);
|
||||||
|
free(comment);
|
||||||
|
free(guest_ok);
|
||||||
|
|
||||||
path = NULL;
|
path = NULL;
|
||||||
comment = NULL;
|
comment = NULL;
|
||||||
guest_ok = NULL;
|
guest_ok = NULL;
|
||||||
@ -179,13 +185,20 @@ smb_retrieve_shares(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (share_file_fp != NULL)
|
if (share_file_fp != NULL) {
|
||||||
fclose(share_file_fp);
|
fclose(share_file_fp);
|
||||||
|
share_file_fp = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
free(name);
|
free(name);
|
||||||
free(path);
|
free(path);
|
||||||
free(comment);
|
free(comment);
|
||||||
free(guest_ok);
|
free(guest_ok);
|
||||||
|
|
||||||
|
name = NULL;
|
||||||
|
path = NULL;
|
||||||
|
comment = NULL;
|
||||||
|
guest_ok = NULL;
|
||||||
}
|
}
|
||||||
closedir(shares_dir);
|
closedir(shares_dir);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user