Skip to content

Commit

Permalink
libbe(3)/bectl(8): Provide and use proper alloc/free for property lists
Browse files Browse the repository at this point in the history
  • Loading branch information
kevans91 committed Jul 25, 2018
1 parent 823f2e5 commit b854d08
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/libbe/be.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const char *be_nextboot_path(libbe_handle_t *);
const char *be_root_path(libbe_handle_t *);

int be_get_bootenv_props(libbe_handle_t *, nvlist_t *);
int be_prop_list_alloc(nvlist_t **be_list);
void be_prop_list_free(nvlist_t *be_list);

int be_activate(libbe_handle_t *, char *, bool);
Expand Down
7 changes: 7 additions & 0 deletions lib/libbe/be_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ prop_list_builder(prop_data_t *data)
}


int
be_prop_list_alloc(nvlist_t **be_list)
{

return (nvlist_alloc(be_list, NV_UNIQUE_NAME, KM_SLEEP));
}

/*
* frees property list and its children
*/
Expand Down
8 changes: 8 additions & 0 deletions lib/libbe/libbe.3
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ of state to be retained, such as errors from previous operations.
.Ft int
.Fn be_add_child "libbe_handle_t *, char *, bool" ;
.Pp
.Ft int
.Fn be_prop_list_alloc "nvlist_t **" ;
.Pp
.Ft int
.Fn be_get_bootenv_props "libbe_handle_t *, nvlist_t *" ;
.Pp
.Ft void
.Fn be_prop_list_free "nvlist_t *" ;
.\" .Ft void
.\" .Fn mp_mfree "MINT *mp" ;
.\" .Bd -ragged -offset indent
Expand Down
6 changes: 3 additions & 3 deletions sbin/bectl/bectl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <sys/param.h>
#include <sys/jail.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <errno.h>
#include <stdbool.h>
Expand Down Expand Up @@ -418,6 +417,7 @@ bectl_cmd_list(int argc, char *argv[])
int opt;
bool show_all_datasets, show_space, hide_headers, show_snaps;

props = NULL;
show_all_datasets = show_space = hide_headers = show_snaps = false;
while ((opt = getopt(argc, argv, "aDHs")) != -1) {
switch (opt) {
Expand Down Expand Up @@ -448,7 +448,7 @@ bectl_cmd_list(int argc, char *argv[])
}


if (nvlist_alloc(&props, NV_UNIQUE_NAME, M_WAITOK) != 0) {
if (be_prop_list_alloc(&props) != 0) {
fprintf(stderr, "bectl list: failed to allocate prop nvlist\n");
return (1);
}
Expand All @@ -459,7 +459,7 @@ bectl_cmd_list(int argc, char *argv[])
}

dump_nvlist(props, 0);
nvlist_free(props);
be_prop_list_free(props);

return (0);
}
Expand Down

0 comments on commit b854d08

Please sign in to comment.