summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/label.c
diff options
context:
space:
mode:
authorKarel Zak2016-05-12 14:37:29 +0200
committerKarel Zak2016-05-12 14:37:29 +0200
commit40c9c3a6b7e6c4cda627d76edb14e92e823451c3 (patch)
tree3ef6c6087834e1ac79f3e7aa855370de4f52e147 /libfdisk/src/label.c
parentlibfdisk: move fdisk_field_...() functions to field.c (diff)
downloadkernel-qcow2-util-linux-40c9c3a6b7e6c4cda627d76edb14e92e823451c3.tar.gz
kernel-qcow2-util-linux-40c9c3a6b7e6c4cda627d76edb14e92e823451c3.tar.xz
kernel-qcow2-util-linux-40c9c3a6b7e6c4cda627d76edb14e92e823451c3.zip
libfdisk: add API for work with labelitems
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/label.c')
-rw-r--r--libfdisk/src/label.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c
index 3410ed9ba..78fc5e78c 100644
--- a/libfdisk/src/label.c
+++ b/libfdisk/src/label.c
@@ -321,10 +321,9 @@ int fdisk_list_disklabel(struct fdisk_context *cxt)
case 's':
if (item.data.str && item.name)
fdisk_info(cxt, "%s: %s", item.name, item.data.str);
- free(item.data.str);
- item.data.str = NULL;
break;
}
+ fdisk_reset_labelitem(&item);
} while (rc == 0 || rc == 1);
return rc < 0 ? rc : 0;
@@ -426,8 +425,11 @@ int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id)
DBG(CXT, ul_debugobj(cxt, "asking for disk %s ID", cxt->label->name));
rc = fdisk_get_disklabel_item(cxt, FDISK_LABELITEM_ID, &item);
- if (rc == 0)
+ if (rc == 0) {
*id = item.data.str;
+ item.data.str = NULL;
+ }
+ fdisk_reset_labelitem(&item);
if (rc > 0)
rc = 0;
return rc;
@@ -441,7 +443,7 @@ int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id)
*
* Note that @id is always in range 0..N. It's fine to use the function in loop
* until it returns error or 2, the result in @item should be ignored when
- * function returns 1.
+ * function returns 1. Don't forget to use fdisk_reset_labelitem() or fdisk_unref_labelitem().
*
* Returns: 0 on success, < 0 on error, 1 on unssupported item, 2 @id out of range
*/
@@ -450,6 +452,7 @@ int fdisk_get_disklabel_item(struct fdisk_context *cxt, int id, struct fdisk_lab
if (!cxt || !cxt->label || !item)
return -EINVAL;
+ fdisk_reset_labelitem(item);
item->id = id;
DBG(CXT, ul_debugobj(cxt, "asking for disk %s item %d", cxt->label->name, item->id));