From 10c39f03a1e70cf2a4b8e0301784174ac5730251 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 22 Jul 2019 12:09:38 +0200 Subject: libfdisk: improve partition copy on resize It seems pretty fragile to copy also reference counting and reference to table list. Addresses: https://github.com/karelzak/util-linux/pull/822 Signed-off-by: Karel Zak --- libfdisk/src/partition.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index 55ce1ca5c..80a43ffde 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -85,7 +85,13 @@ static struct fdisk_partition *__copy_partition(struct fdisk_partition *o) if (!n) return NULL; + memcpy(n, o, sizeof(*n)); + + /* do not copy reference to lists, etc.*/ + n->refcount = 1; + INIT_LIST_HEAD(&n->parts); + if (n->type) fdisk_ref_parttype(n->type); if (o->name) -- cgit v1.2.3-55-g7522