Commit 97f3ad35 authored by Markus Armbruster's avatar Markus Armbruster Committed by Amit Shah
Browse files

migration: Use g_new() & friends where that makes obvious sense



g_new(T, n) is neater than g_malloc(sizeof(T) * n).  It's also safer,
for two reasons.  One, it catches multiplication overflowing size_t.
Two, it returns T * rather than void *, which lets the compiler catch
more type errors.

This commit only touches allocations with size arguments of the form
sizeof(T).  Same Coccinelle semantic patch as in commit b45c03f5.

Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
Message-Id: <1442231491-23352-1-git-send-email-armbru@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Reviewed-by: default avatarzhanghailiang <zhang.zhanghailiang@huawei.com>
Reviewed-by: default avatarAmit Shah <amit.shah@redhat.com>
Signed-off-by: default avatarAmit Shah <amit.shah@redhat.com>
parent 56f3835f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -86,7 +86,7 @@ MigrationIncomingState *migration_incoming_get_current(void)

MigrationIncomingState *migration_incoming_state_new(QEMUFile* f)
{
    mis_current = g_malloc0(sizeof(MigrationIncomingState));
    mis_current = g_new0(MigrationIncomingState, 1);
    mis_current->file = f;
    QLIST_INIT(&mis_current->loadvm_handlers);

+1 −1
Original line number Diff line number Diff line
@@ -440,7 +440,7 @@ QEMUFile *qemu_bufopen(const char *mode, QEMUSizedBuffer *input)
        return NULL;
    }

    s = g_malloc0(sizeof(QEMUBuffer));
    s = g_new0(QEMUBuffer, 1);
    s->qsb = input;

    if (s->qsb == NULL) {
+2 −2
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode)
        return NULL;
    }

    s = g_malloc0(sizeof(QEMUFileStdio));
    s = g_new0(QEMUFileStdio, 1);

    s->stdio_file = stdio_file;

@@ -176,7 +176,7 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
        return NULL;
    }

    s = g_malloc0(sizeof(QEMUFileStdio));
    s = g_new0(QEMUFileStdio, 1);

    s->stdio_file = fopen(filename, mode);
    if (!s->stdio_file) {
+2 −2
Original line number Diff line number Diff line
@@ -194,7 +194,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
        return NULL;
    }

    s = g_malloc0(sizeof(QEMUFileSocket));
    s = g_new0(QEMUFileSocket, 1);
    s->fd = fd;

    if (mode[0] == 'r') {
@@ -228,7 +228,7 @@ QEMUFile *qemu_fopen_socket(int fd, const char *mode)
        return NULL;
    }

    s = g_malloc0(sizeof(QEMUFileSocket));
    s = g_new0(QEMUFileSocket, 1);
    s->fd = fd;
    if (mode[0] == 'w') {
        qemu_set_block(s->fd);
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops)
{
    QEMUFile *f;

    f = g_malloc0(sizeof(QEMUFile));
    f = g_new0(QEMUFile, 1);

    f->opaque = opaque;
    f->ops = ops;
Loading