From a50c849007f02ccb4bd15107da53f27c8ce9b41c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 27 Oct 2016 10:51:59 +0200 Subject: libfdisk: cleanup labelitem initialization * use macro for label initialization * make sure we do not call fdisk_ref_labelitem() and fdisk_unref_labelitem() for non-allocated items Signed-off-by: Karel Zak --- libfdisk/src/fdiskP.h | 4 ++++ libfdisk/src/item.c | 8 +++++++- libfdisk/src/label.c | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'libfdisk') diff --git a/libfdisk/src/fdiskP.h b/libfdisk/src/fdiskP.h index 159823c45..c624773db 100644 --- a/libfdisk/src/fdiskP.h +++ b/libfdisk/src/fdiskP.h @@ -433,6 +433,10 @@ struct fdisk_labelitem { } data; }; +/* Use only internally for non-allocated items, never use + * refcouting for such items! + */ +#define FDISK_LABELITEM_INIT { .type = 0, .refcount = 0 } /* ask.c */ struct fdisk_ask *fdisk_new_ask(void); diff --git a/libfdisk/src/item.c b/libfdisk/src/item.c index 7809b5e03..31637a1f1 100644 --- a/libfdisk/src/item.c +++ b/libfdisk/src/item.c @@ -52,8 +52,11 @@ struct fdisk_labelitem *fdisk_new_labelitem(void) */ void fdisk_ref_labelitem(struct fdisk_labelitem *li) { - if (li) + if (li) { + /* me sure we do not use refcouting for static items */ + assert(li->refcount > 0); li->refcount++; + } } /** @@ -94,6 +97,9 @@ void fdisk_unref_labelitem(struct fdisk_labelitem *li) if (!li) return; + /* me sure we do not use refcouting for static items */ + assert(li->refcount > 0); + li->refcount--; if (li->refcount <= 0) { DBG(ITEM, ul_debugobj(li, "free")); diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 0e83fdf34..52f9ec5ea 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -416,7 +416,7 @@ int fdisk_locate_disklabel(struct fdisk_context *cxt, int n, const char **name, */ int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id) { - struct fdisk_labelitem item = {0}; + struct fdisk_labelitem item = FDISK_LABELITEM_INIT; int rc; if (!cxt || !cxt->label || !id) -- cgit v1.2.3-55-g7522