diff options
author | Andriy Gapon <avg@FreeBSD.org> | 2019-12-03 09:48:43 +0000 |
---|---|---|
committer | Andriy Gapon <avg@FreeBSD.org> | 2019-12-03 09:48:43 +0000 |
commit | 84a03ac69a4b633526bc775fe73c973b1f0769b7 (patch) | |
tree | b26d6ca33fdea3a3001ebb13fe78027fe66cf25e /lib/libdevstat | |
parent | 3995097fdec1a9121eaaf57f650c7fefb4eea5e7 (diff) | |
download | src-84a03ac69a4b633526bc775fe73c973b1f0769b7.tar.gz src-84a03ac69a4b633526bc775fe73c973b1f0769b7.zip |
Notes
Diffstat (limited to 'lib/libdevstat')
-rw-r--r-- | lib/libdevstat/devstat.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/libdevstat/devstat.c b/lib/libdevstat/devstat.c index 2da7eafa4fd8..047a2a79204d 100644 --- a/lib/libdevstat/devstat.c +++ b/lib/libdevstat/devstat.c @@ -584,10 +584,10 @@ devstat_selectdevs(struct device_selection **dev_select, int *num_selected, * In this case, we have selected devices before, but the device * list has changed since we last selected devices, so we need to * either enlarge or reduce the size of the device selection list. + * But delay the resizing until after copying the data to old_dev_select + * as to not lose any data in the case of reducing the size. */ } else if (*num_selections != numdevs) { - *dev_select = (struct device_selection *)reallocf(*dev_select, - numdevs * sizeof(struct device_selection)); *select_generation = current_generation; init_selections = 1; /* @@ -645,6 +645,11 @@ devstat_selectdevs(struct device_selection **dev_select, int *num_selected, sizeof(struct device_selection) * *num_selections); } + if (!changed && *num_selections != numdevs) { + *dev_select = (struct device_selection *)reallocf(*dev_select, + numdevs * sizeof(struct device_selection)); + } + if (init_selections != 0) { bzero(*dev_select, sizeof(struct device_selection) * numdevs); |