]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: cleanup labelitem initialization
authorKarel Zak <kzak@redhat.com>
Thu, 27 Oct 2016 08:51:59 +0000 (10:51 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 27 Oct 2016 08:53:55 +0000 (10:53 +0200)
* 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>
libfdisk/src/fdiskP.h
libfdisk/src/item.c
libfdisk/src/label.c

index 159823c450d3f53c413c8a8d18be506f7d3589f4..c624773db5ba7cbeb295d77171f175f981fbde2e 100644 (file)
@@ -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);
index 7809b5e032ea103790be71761a7ea77aa0159262..31637a1f1df5399fbef8566bdd9e362f872339fc 100644 (file)
@@ -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"));
index 0e83fdf34bbc04f05735ed5ee25aeed537e48b1e..52f9ec5ea7639634a46f186f6102718ea7264af2 100644 (file)
@@ -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)