diff options
author | Karel Zak | 2016-10-27 10:51:59 +0200 |
---|---|---|
committer | Karel Zak | 2016-10-27 10:53:55 +0200 |
commit | a50c849007f02ccb4bd15107da53f27c8ce9b41c (patch) | |
tree | 3e5e739bfb41208e7b368ea6d05dd4b732bcd900 /libfdisk | |
parent | libfdisk: fix uninitialized fdisk_labelitem (diff) | |
download | kernel-qcow2-util-linux-a50c849007f02ccb4bd15107da53f27c8ce9b41c.tar.gz kernel-qcow2-util-linux-a50c849007f02ccb4bd15107da53f27c8ce9b41c.tar.xz kernel-qcow2-util-linux-a50c849007f02ccb4bd15107da53f27c8ce9b41c.zip |
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 <kzak@redhat.com>
Diffstat (limited to 'libfdisk')
-rw-r--r-- | libfdisk/src/fdiskP.h | 4 | ||||
-rw-r--r-- | libfdisk/src/item.c | 8 | ||||
-rw-r--r-- | libfdisk/src/label.c | 2 |
3 files changed, 12 insertions, 2 deletions
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) |