Skip to content

Commit

Permalink
12801 libdiskmgt leaks PROM device information handles like a sieve
Browse files Browse the repository at this point in the history
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Reviewed by: Yuri Pankov <yuripv@yuripv.dev>
Approved by: Richard Lowe <richlowe@richlowe.net>
  • Loading branch information
jclulow committed Aug 6, 2020
1 parent bd05d33 commit be235d1
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions usr/src/lib/libdiskmgt/common/findevs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/*
* Copyright (c) 2011 by Delphix. All rights reserved.
* Copyright 2017 Nexenta Systems, Inc.
* Copyright 2020 Oxide Computer Company
*/

#include <fcntl.h>
Expand Down Expand Up @@ -149,26 +150,47 @@ findevs(struct search_args *args)
args->controller_listp = NULL;
args->disk_listp = NULL;

args->ph = DI_PROM_HANDLE_NIL;
args->handle = DI_LINK_NIL;
args->dev_walk_status = 0;
args->handle = di_devlink_init(NULL, 0);

/*
* Create device information library handles, which must be destroyed
* before we return.
*/
if ((args->ph = di_prom_init()) == DI_PROM_HANDLE_NIL ||
(args->handle = di_devlink_init(NULL, 0)) == DI_LINK_NIL) {
/*
* We could not open all of the handles we need, so clean up
* and report failure to the caller.
*/
args->dev_walk_status = errno;
goto cleanup;
}

/*
* Have to make several passes at this with the new devfs caching.
* First, we find non-mpxio devices. Then we find mpxio/multipath
* devices.
*/
di_root = di_init("/", DINFOCACHE);
args->ph = di_prom_init();
(void) di_walk_minor(di_root, NULL, 0, args, add_devs);
di_fini(di_root);

di_root = di_init("/", DINFOCPYALL|DINFOPATH);
(void) di_walk_minor(di_root, NULL, 0, args, add_devs);
di_fini(di_root);

(void) di_devlink_fini(&(args->handle));

clean_paths(args);

cleanup:
if (args->ph != DI_PROM_HANDLE_NIL) {
di_prom_fini(args->ph);
args->ph = DI_PROM_HANDLE_NIL;
}
if (args->handle != DI_LINK_NIL) {
(void) di_devlink_fini(&(args->handle));
}
}

/*
Expand Down

0 comments on commit be235d1

Please sign in to comment.