mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
qga: 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 b45c03f
.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
This commit is contained in:
parent
fafcaf1d74
commit
f3a06403b8
6 changed files with 17 additions and 17 deletions
|
@ -106,7 +106,7 @@ static int64_t guest_file_handle_add(HANDLE fh, Error **errp)
|
|||
if (handle < 0) {
|
||||
return -1;
|
||||
}
|
||||
gfh = g_malloc0(sizeof(GuestFileHandle));
|
||||
gfh = g_new0(GuestFileHandle, 1);
|
||||
gfh->id = handle;
|
||||
gfh->fh = fh;
|
||||
QTAILQ_INSERT_TAIL(&guest_file_state.filehandles, gfh, next);
|
||||
|
@ -298,7 +298,7 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
|
|||
slog("guest-file-read failed, handle %" PRId64, handle);
|
||||
} else {
|
||||
buf[read_count] = 0;
|
||||
read_data = g_malloc0(sizeof(GuestFileRead));
|
||||
read_data = g_new0(GuestFileRead, 1);
|
||||
read_data->count = (size_t)read_count;
|
||||
read_data->eof = read_count == 0;
|
||||
|
||||
|
@ -342,7 +342,7 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,
|
|||
error_setg_win32(errp, GetLastError(), "failed to write to file");
|
||||
slog("guest-file-write-failed, handle: %" PRId64, handle);
|
||||
} else {
|
||||
write_data = g_malloc0(sizeof(GuestFileWrite));
|
||||
write_data = g_new0(GuestFileWrite, 1);
|
||||
write_data->count = (size_t) write_count;
|
||||
}
|
||||
|
||||
|
@ -865,7 +865,7 @@ static DWORD WINAPI do_suspend(LPVOID opaque)
|
|||
void qmp_guest_suspend_disk(Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
GuestSuspendMode *mode = g_malloc(sizeof(GuestSuspendMode));
|
||||
GuestSuspendMode *mode = g_new(GuestSuspendMode, 1);
|
||||
|
||||
*mode = GUEST_SUSPEND_MODE_DISK;
|
||||
check_suspend_mode(*mode, &local_err);
|
||||
|
@ -881,7 +881,7 @@ void qmp_guest_suspend_disk(Error **errp)
|
|||
void qmp_guest_suspend_ram(Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
GuestSuspendMode *mode = g_malloc(sizeof(GuestSuspendMode));
|
||||
GuestSuspendMode *mode = g_new(GuestSuspendMode, 1);
|
||||
|
||||
*mode = GUEST_SUSPEND_MODE_RAM;
|
||||
check_suspend_mode(*mode, &local_err);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue