Set dp to NULL when we free it, and tree a NULL dp as an error

condition. This should prevent a double free. In addition, prevent a
leak by freeing dp each loop and when we're done.

CID: 1383577
Sponsored by: Netflix
This commit is contained in:
imp 2018-01-05 07:09:24 +00:00
parent 6fb458c8b6
commit 6bb28aae18
2 changed files with 6 additions and 1 deletions

View File

@ -663,6 +663,7 @@ path_to_dp(struct gmesh *mesh, char *path, efidp *dp)
free(rp);
if (rv != 0) {
free(*dp);
*dp = NULL;
}
return (rv);
}

View File

@ -143,10 +143,13 @@ unix_to_efi(void)
char *walker;
int rv;
dp = NULL;
while (fgets(buffer, sizeof(buffer), stdin)) {
walker= trim(buffer);
free(dp);
dp = NULL;
rv = efivar_unix_path_to_device_path(walker, &dp);
if (rv != 0) {
if (rv != 0 || dp == NULL) {
errno = rv;
warn("Can't convert '%s' to efi", walker);
continue;
@ -158,6 +161,7 @@ unix_to_efi(void)
}
printf("%s\n", efi);
}
free(dp);
}
static void