[Sheepdog] [PATCH] sheepdog: use qemu_malloc()/qemu_free() instead of malloc()/free()
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Fri Apr 30 09:33:26 CEST 2010
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
block/sheepdog.c | 38 ++++++++++++++++++--------------------
1 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c
index a2c08a0..8e9a4fa 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -822,7 +822,7 @@ static int parse_vdiname(const char *filename, char *vdi, int vdi_len,
} else
*snapid = CURRENT_VDI_ID; /* search current vdi */
- free(q);
+ qemu_free(q);
return 0;
}
@@ -983,7 +983,7 @@ static int sd_open(BlockDriverState *bs, const char *filename, int flags)
int for_snapshot = 0, dummy;
char *buf;
- buf = malloc(SD_INODE_SIZE);
+ buf = qemu_malloc(SD_INODE_SIZE);
if (!buf) {
eprintf("Failed to allocate memory\n");
return -1;
@@ -1023,12 +1023,12 @@ static int sd_open(BlockDriverState *bs, const char *filename, int flags)
bs->total_sectors = s->inode.vdi_size >> 9;
s->name = strdup(vdi);
- free(buf);
+ qemu_free(buf);
QLIST_INIT(&s->pending_head);
return 0;
out:
- free(buf);
+ qemu_free(buf);
return -1;
}
@@ -1100,7 +1100,7 @@ static int sd_create(const char *filename, QEMUOptionParameter *options)
memset(&bs, 0, sizeof(bs));
- bs.opaque = malloc(sizeof(struct bdrv_sd_state));
+ bs.opaque = qemu_malloc(sizeof(struct bdrv_sd_state));
if (!bs.opaque)
return -1;
@@ -1128,7 +1128,7 @@ static void sd_close(BlockDriverState *bs)
struct bdrv_sd_state *s = bs->opaque;
close(s->fd);
- free(s->name);
+ qemu_free(s->name);
}
static int sd_claim(BlockDriverState *bs)
@@ -1261,7 +1261,7 @@ static int sd_create_branch(struct bdrv_sd_state *s)
eprintf("%" PRIx32 " is not current.\n", s->inode.vdi_id);
- buf = malloc(SD_INODE_SIZE);
+ buf = qemu_malloc(SD_INODE_SIZE);
if (!buf)
return -1;
@@ -1285,7 +1285,7 @@ static int sd_create_branch(struct bdrv_sd_state *s)
eprintf("%" PRIx32 " was newly created.\n", s->inode.vdi_id);
out:
- free(buf);
+ qemu_free(buf);
return ret;
}
@@ -1490,7 +1490,7 @@ static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
goto cleanup;
}
- inode = (struct sd_inode *)malloc(sizeof(struct sd_inode));
+ inode = (struct sd_inode *)qemu_malloc(sizeof(struct sd_inode));
if (!inode) {
eprintf("failed to allocate memory for inode. %m\n");
goto cleanup;
@@ -1523,7 +1523,7 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
sd_release(bs);
- old_s = malloc(sizeof(struct bdrv_sd_state));
+ old_s = qemu_malloc(sizeof(struct bdrv_sd_state));
if (!old_s) {
eprintf("failed to allocate memory for old state. %m\n");
goto out;
@@ -1537,7 +1537,7 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
goto out;
}
- buf = malloc(SD_INODE_SIZE);
+ buf = qemu_malloc(SD_INODE_SIZE);
if (!buf) {
eprintf("Failed to allocate memory\n");
goto out;
@@ -1566,15 +1566,15 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
s->is_current = 0;
- free(buf);
- free(old_s);
+ qemu_free(buf);
+ qemu_free(old_s);
return 0;
out:
/* recover bdrv_sd_state */
memcpy(s, old_s, sizeof(struct bdrv_sd_state));
- free(buf);
- free(old_s);
+ qemu_free(buf);
+ qemu_free(old_s);
eprintf("failed to open. recover old bdrv_sd_state.\n");
@@ -1613,7 +1613,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
unsigned long *vdi_inuse;
unsigned int start_nr;
- vdi_inuse = malloc(max);
+ vdi_inuse = qemu_malloc(max);
if (!vdi_inuse)
return 0;
@@ -1635,12 +1635,10 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
if (ret)
goto out;
- sn_tab = malloc(nr * sizeof(*sn_tab));
+ sn_tab = qemu_mallocz(nr * sizeof(*sn_tab));
if (!sn_tab)
goto out;
- memset(sn_tab, 0, nr * sizeof(*sn_tab));
-
start_nr = fnv_64a_buf(s->name, strlen(s->name), FNV1A_64_INIT) & (SD_NR_VDIS - 1);
/* TODO: round up */
@@ -1668,7 +1666,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)
out:
*psn_tab = sn_tab;
- free(vdi_inuse);
+ qemu_free(vdi_inuse);
return found;
}
--
1.5.6.5
More information about the sheepdog
mailing list