* 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>
} 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);
*/
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++;
+ }
}
/**
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"));
*/
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)