Skip to contentSkip to conversation

block: replace unchecked strdup/malloc/calloc with glib

PATCH Applied Stefan Hajnoczi 2 participants 2 messages Jan 16, 2012 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: replace unchecked strdup/malloc/calloc with glib

Most of the codebase as been converted to use glib memory allocation functions. There are still a few instances of malloc/calloc in the block layer and qemu-io. Replace them, especially since they do not check the strdup/malloc/calloc return value.

---
 block/blkdebug.c  |    4 ++--
 block/blkverify.c |    4 ++--
 qemu-io.c         |   48 ++++++++++++++++++++++++------------------------
 3 files changed, 28 insertions(+), 28 deletions(-)
block/blkdebug.c +2 -2
index 9b88535..a251802 100644
@@ -292,10 +292,10 @@ static int blkdebug_open(BlockDriverState *bs, const char *filename, int flags)
         return -EINVAL;
     }
 
-    config = strdup(filename);
+    config = g_strdup(filename);
     config[c - filename] = '\0';
     ret = read_config(s, config);
-    free(config);
+    g_free(config);
     if (ret < 0) {
         return ret;
     }
block/blkverify.c +2 -2
index 4ca8584..9d5f1ec 100644
@@ -87,10 +87,10 @@ static int blkverify_open(BlockDriverState *bs, const char *filename, int flags)
         return -EINVAL;
     }
 
-    raw = strdup(filename);
+    raw = g_strdup(filename);
     raw[c - filename] = '\0';
     ret = bdrv_file_open(&bs->file, raw, flags);
-    free(raw);
+    g_free(raw);
     if (ret < 0) {
         return ret;
     }
qemu-io.c +24 -24

187 lines not on this page · raw message

Signature · 1 line
1.7.8.3
Applied
#1 lore raw

Am 16.01.2012 10:28, schrieb Stefan Hajnoczi:

Quoted 7 lines

Most of the codebase as been converted to use glib memory allocation functions. There are still a few instances of malloc/calloc in the block layer and qemu-io. Replace them, especially since they do not check the strdup/malloc/calloc return value.

Thanks, applied to the block branch.

Kevin