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:
Warner Losh 2018-01-05 07:09:24 +00:00
parent 63b5669494
commit 167b7a41ff
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=327574
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); free(rp);
if (rv != 0) { if (rv != 0) {
free(*dp); free(*dp);
*dp = NULL;
} }
return (rv); return (rv);
} }

View file

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