Merge remote-tracking branch 'stefanha/trivial-patches' into staging

# By Markus Armbruster (12) and others
# Via Stefan Hajnoczi
* stefanha/trivial-patches:
  qmp-commands.hx: s/tray-open/tray_open/ to match qapi schema
  tests: Fix {rtc, m48t59}-test build on illumos
  qemu-pixman.h: Avoid mutual inclusion loop with console.h
  qemu-ga: Fix unchecked strdup() by converting to g_strdup()
  qapi: Fix unchecked strdup() by converting to g_strdup()
  libcacard: Fix unchecked strdup() by converting to g_strdup()
  qemu-log: Plug trivial memory leak in cpu_set_log_filename()
  qemu-log: Fix unchecked strdup() by converting to g_strdup()
  virtfs-proxy-helper: Fix unchecked strdup() by conv. to g_strdup()
  spice: Fix unchecked strdup() by converting to g_strdup()
  readline: Fix unchecked strdup() by converting to g_strdup()
  hw/9pfs: Fix unchecked strdup() by converting to g_strdup()
  g_strdup(NULL) returns NULL; simplify
  g_malloc(0) and g_malloc0(0) return NULL; simplify
  xilinx_axidma: Fix debug mode compile messages
  cadence_gem: Debug mode compile fixes
  cadence_ttc: Debug mode compile fixes
  vnc: Clean up vncws_send_handshake_response()
This commit is contained in:
Anthony Liguori 2013-01-30 10:51:18 -06:00
commit b0df98f3a2
29 changed files with 68 additions and 82 deletions

View file

@ -737,11 +737,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
* l1_table_offset when it is the current s->l1_table_offset! Be careful
* when changing this! */
if (l1_table_offset != s->l1_table_offset) {
if (l1_size2 != 0) {
l1_table = g_malloc0(align_offset(l1_size2, 512));
} else {
l1_table = NULL;
}
l1_table = g_malloc0(align_offset(l1_size2, 512));
l1_allocated = 1;
if (bdrv_pread(bs->file, l1_table_offset,
l1_table, l1_size2) != l1_size2)

View file

@ -443,9 +443,7 @@ static int vdi_open(BlockDriverState *bs, int flags)
bmap_size = header.blocks_in_image * sizeof(uint32_t);
bmap_size = (bmap_size + SECTOR_SIZE - 1) / SECTOR_SIZE;
if (bmap_size > 0) {
s->bmap = g_malloc(bmap_size * SECTOR_SIZE);
}
s->bmap = g_malloc(bmap_size * SECTOR_SIZE);
ret = bdrv_read(bs->file, s->bmap_sector, (uint8_t *)s->bmap, bmap_size);
if (ret < 0) {
goto fail_free_bmap;

View file

@ -1039,7 +1039,7 @@ int main(int argc, char **argv)
}
switch (c) {
case 'p':
rpath = strdup(optarg);
rpath = g_strdup(optarg);
break;
case 'n':
is_daemon = false;
@ -1048,7 +1048,7 @@ int main(int argc, char **argv)
sock = atoi(optarg);
break;
case 's':
sock_name = strdup(optarg);
sock_name = g_strdup(optarg);
break;
case 'u':
own_u = atoi(optarg);

View file

@ -85,11 +85,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
}
s->ctx.export_flags = fse->export_flags;
if (fse->path) {
s->ctx.fs_root = g_strdup(fse->path);
} else {
s->ctx.fs_root = NULL;
}
s->ctx.fs_root = g_strdup(fse->path);
s->ctx.exops.get_st_gen = NULL;
len = strlen(conf->tag);
if (len > MAX_TAG_LEN - 1) {
@ -98,7 +94,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
exit(1);
}
s->tag = strdup(conf->tag);
s->tag = g_strdup(conf->tag);
s->ctx.uid = -1;
s->ops = fse->ops;

View file

@ -46,7 +46,7 @@ static const char *local_mapped_attr_path(FsContext *ctx,
const char *path, char *buffer)
{
char *dir_name;
char *tmp_path = strdup(path);
char *tmp_path = g_strdup(path);
char *base_name = basename(tmp_path);
/* NULL terminate the directory */
@ -55,7 +55,7 @@ static const char *local_mapped_attr_path(FsContext *ctx,
snprintf(buffer, PATH_MAX, "%s/%s/%s/%s",
ctx->fs_root, dir_name, VIRTFS_META_DIR, base_name);
free(tmp_path);
g_free(tmp_path);
return buffer;
}
@ -130,7 +130,7 @@ static int local_create_mapped_attr_dir(FsContext *ctx, const char *path)
{
int err;
char attr_dir[PATH_MAX];
char *tmp_path = strdup(path);
char *tmp_path = g_strdup(path);
snprintf(attr_dir, PATH_MAX, "%s/%s/%s",
ctx->fs_root, dirname(tmp_path), VIRTFS_META_DIR);
@ -139,7 +139,7 @@ static int local_create_mapped_attr_dir(FsContext *ctx, const char *path)
if (err < 0 && errno == EEXIST) {
err = 0;
}
free(tmp_path);
g_free(tmp_path);
return err;
}

View file

@ -3101,11 +3101,7 @@ static void v9fs_xattrcreate(void *opaque)
xattr_fidp->fs.xattr.flags = flags;
v9fs_string_init(&xattr_fidp->fs.xattr.name);
v9fs_string_copy(&xattr_fidp->fs.xattr.name, &name);
if (size) {
xattr_fidp->fs.xattr.value = g_malloc(size);
} else {
xattr_fidp->fs.xattr.value = NULL;
}
xattr_fidp->fs.xattr.value = g_malloc(size);
err = offset;
put_fid(pdu, file_fidp);
out_nofid:

View file

@ -18,9 +18,7 @@ void blkconf_serial(BlockConf *conf, char **serial)
if (!*serial) {
/* try to fall back to value set with legacy -drive serial=... */
dinfo = drive_get_by_blockdev(conf->bs);
if (dinfo->serial) {
*serial = g_strdup(dinfo->serial);
}
*serial = g_strdup(dinfo->serial);
}
}

View file

@ -687,14 +687,15 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
packet_desc_addr = s->rx_desc_addr;
while (1) {
DB_PRINT("read descriptor 0x%x\n", packet_desc_addr);
DB_PRINT("read descriptor 0x%x\n", (unsigned)packet_desc_addr);
/* read current descriptor */
cpu_physical_memory_read(packet_desc_addr,
(uint8_t *)&desc[0], sizeof(desc));
/* Descriptor owned by software ? */
if (rx_desc_get_ownership(desc) == 1) {
DB_PRINT("descriptor 0x%x owned by sw.\n", packet_desc_addr);
DB_PRINT("descriptor 0x%x owned by sw.\n",
(unsigned)packet_desc_addr);
s->regs[GEM_RXSTATUS] |= GEM_RXSTATUS_NOBUF;
/* Handle interrupt consequences */
gem_update_int_status(s);
@ -709,7 +710,7 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
*/
if (rx_desc_get_buffer(desc) == 0) {
DB_PRINT("Invalid RX buffer (NULL) for descriptor 0x%x\n",
packet_desc_addr);
(unsigned)packet_desc_addr);
break;
}
@ -749,7 +750,7 @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size)
s->rx_desc_addr += 8;
}
DB_PRINT("set SOF, OWN on descriptor 0x%08x\n", packet_desc_addr);
DB_PRINT("set SOF, OWN on descriptor 0x%08x\n", (unsigned)packet_desc_addr);
/* Count it */
gem_receive_updatestats(s, buf, size);
@ -861,7 +862,8 @@ static void gem_transmit(GemState *s)
*/
if ((tx_desc_get_buffer(desc) == 0) ||
(tx_desc_get_length(desc) == 0)) {
DB_PRINT("Invalid TX descriptor @ 0x%x\n", packet_desc_addr);
DB_PRINT("Invalid TX descriptor @ 0x%x\n",
(unsigned)packet_desc_addr);
break;
}
@ -1031,10 +1033,11 @@ static uint64_t gem_read(void *opaque, hwaddr offset, unsigned size)
offset >>= 2;
retval = s->regs[offset];
DB_PRINT("offset: 0x%04x read: 0x%08x\n", offset*4, retval);
DB_PRINT("offset: 0x%04x read: 0x%08x\n", (unsigned)offset*4, retval);
switch (offset) {
case GEM_ISR:
DB_PRINT("lowering irq on ISR read\n");
qemu_set_irq(s->irq, 0);
break;
case GEM_PHYMNTNC:
@ -1073,7 +1076,7 @@ static void gem_write(void *opaque, hwaddr offset, uint64_t val,
GemState *s = (GemState *)opaque;
uint32_t readonly;
DB_PRINT("offset: 0x%04x write: 0x%08x ", offset, (unsigned)val);
DB_PRINT("offset: 0x%04x write: 0x%08x ", (unsigned)offset, (unsigned)val);
offset >>= 2;
/* Squash bits which are read only in write value */

View file

@ -302,7 +302,7 @@ static uint64_t cadence_ttc_read(void *opaque, hwaddr offset,
{
uint32_t ret = cadence_ttc_read_imp(opaque, offset);
DB_PRINT("addr: %08x data: %08x\n", offset, ret);
DB_PRINT("addr: %08x data: %08x\n", (unsigned)offset, (unsigned)ret);
return ret;
}
@ -311,7 +311,7 @@ static void cadence_ttc_write(void *opaque, hwaddr offset,
{
CadenceTimerState *s = cadence_timer_from_addr(opaque, offset);
DB_PRINT("addr: %08x data %08x\n", offset, (unsigned)value);
DB_PRINT("addr: %08x data %08x\n", (unsigned)offset, (unsigned)value);
cadence_timer_sync(s);

View file

@ -269,11 +269,8 @@ static inline void vhost_dev_log_resize(struct vhost_dev* dev, uint64_t size)
vhost_log_chunk_t *log;
uint64_t log_base;
int r, i;
if (size) {
log = g_malloc0(size * sizeof *log);
} else {
log = NULL;
}
log = g_malloc0(size * sizeof *log);
log_base = (uint64_t)(unsigned long)log;
r = ioctl(dev->control, VHOST_SET_LOG_BASE, &log_base);
assert(r >= 0);

View file

@ -444,7 +444,7 @@ static void axidma_write(void *opaque, hwaddr addr,
break;
default:
D(qemu_log("%s: ch=%d addr=" TARGET_FMT_plx " v=%x\n",
__func__, sid, addr * 4, value));
__func__, sid, addr * 4, (unsigned)value));
s->regs[addr] = value;
break;
}

View file

@ -15,7 +15,7 @@
#pragma GCC diagnostic error "-Wredundant-decls"
#endif
#include "console.h"
#include "qemu/typedefs.h"
/*
* pixman image formats are defined to be native endian,

View file

@ -21,6 +21,7 @@
#include "qemu/thread.h"
#include "ui/qemu-pixman.h"
#include "ui/console.h"
#include "sysemu/sysemu.h"
#define NUM_MEMSLOTS 8

View file

@ -454,7 +454,7 @@ vreader_emul_new(PK11SlotInfo *slot, VCardEmulType type, const char *params)
new_reader_emul->slot = PK11_ReferenceSlot(slot);
new_reader_emul->default_type = type;
new_reader_emul->type_params = strdup(params);
new_reader_emul->type_params = g_strdup(params);
new_reader_emul->present = PR_FALSE;
new_reader_emul->series = 0;
new_reader_emul->saved_vcard = NULL;
@ -997,7 +997,7 @@ vcard_emul_init(const VCardEmulOptions *options)
/* We should control this with options. For now we mirror out any
* removable hardware slot */
default_card_type = options->hw_card_type;
default_type_params = strdup(options->hw_type_params);
default_type_params = g_strdup(options->hw_type_params);
SECMOD_GetReadLock(module_lock);
for (mlp = module_list; mlp; mlp = mlp->next) {

View file

@ -49,7 +49,7 @@ vreader_new(const char *name, VReaderEmul *private,
reader = (VReader *)g_malloc(sizeof(VReader));
qemu_mutex_init(&reader->lock);
reader->reference_count = 1;
reader->name = name ? strdup(name) : NULL;
reader->name = g_strdup(name);
reader->card = NULL;
reader->id = (vreader_id_t)-1;
reader->reader_private = private;

View file

@ -503,8 +503,8 @@ main(
command_line_options = vcard_emul_options(emul_args);
}
qemu_host = strdup(argv[argc - 2]);
qemu_port = strdup(argv[argc - 1]);
qemu_host = g_strdup(argv[argc - 2]);
qemu_port = g_strdup(argv[argc - 1]);
sock = connect_to_qemu(qemu_host, qemu_port);
if (sock == -1) {
fprintf(stderr, "error opening socket, exiting.\n");

View file

@ -566,9 +566,7 @@ static int net_init_nic(const NetClientOptions *opts, const char *name,
assert(peer);
nd->netdev = peer;
}
if (name) {
nd->name = g_strdup(name);
}
nd->name = g_strdup(name);
if (nic->has_model) {
nd->model = g_strdup(nic->model);
}

View file

@ -92,7 +92,7 @@ char **qmp_get_command_list(void)
list_head = list = g_malloc0(count * sizeof(char *));
QTAILQ_FOREACH(cmd, &qmp_commands, node) {
*list = strdup(cmd->name);
*list = g_strdup(cmd->name);
list++;
}

View file

@ -21,10 +21,12 @@
#include "qemu/log.h"
#ifdef WIN32
static const char *logfilename = "qemu.log";
#define DEFAULT_LOGFILENAME "qemu.log"
#else
static const char *logfilename = "/tmp/qemu.log";
#define DEFAULT_LOGFILENAME "/tmp/qemu.log"
#endif
static char *logfilename;
FILE *qemu_logfile;
int qemu_loglevel;
static int log_append = 0;
@ -54,11 +56,13 @@ void qemu_log_mask(int mask, const char *fmt, ...)
/* enable or disable low levels log */
void qemu_set_log(int log_flags, bool use_own_buffers)
{
const char *fname = logfilename ?: DEFAULT_LOGFILENAME;
qemu_loglevel = log_flags;
if (qemu_loglevel && !qemu_logfile) {
qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
qemu_logfile = fopen(fname, log_append ? "a" : "w");
if (!qemu_logfile) {
perror(logfilename);
perror(fname);
_exit(1);
}
/* must avoid mmap() usage of glibc by setting a buffer "by hand" */
@ -84,7 +88,8 @@ void qemu_set_log(int log_flags, bool use_own_buffers)
void cpu_set_log_filename(const char *filename)
{
logfilename = strdup(filename);
g_free(logfilename);
logfilename = g_strdup(filename);
if (qemu_logfile) {
fclose(qemu_logfile);
qemu_logfile = NULL;

View file

@ -61,7 +61,7 @@ struct GuestAgentInfo *qmp_guest_info(Error **err)
while (*cmd_list) {
cmd_info = g_malloc0(sizeof(GuestAgentCommandInfo));
cmd_info->name = strdup(*cmd_list);
cmd_info->name = g_strdup(*cmd_list);
cmd_info->enabled = qmp_command_is_enabled(cmd_info->name);
cmd_info_list = g_malloc0(sizeof(GuestAgentCommandInfoList));

View file

@ -1659,7 +1659,7 @@ Each json-object contain the following:
- Possible values: "unknown"
- "removable": true if the device is removable, false otherwise (json-bool)
- "locked": true if the device is locked, false otherwise (json-bool)
- "tray-open": only present if removable, true if the device has a tray,
- "tray_open": only present if removable, true if the device has a tray,
and it is open (json-bool)
- "inserted": only present if the device is inserted, it is a json-object
containing the following:

View file

@ -247,14 +247,14 @@ static void readline_hist_add(ReadLineState *rs, const char *cmdline)
}
if (idx == READLINE_MAX_CMDS) {
/* Need to get one free slot */
free(rs->history[0]);
g_free(rs->history[0]);
memmove(rs->history, &rs->history[1],
(READLINE_MAX_CMDS - 1) * sizeof(char *));
rs->history[READLINE_MAX_CMDS - 1] = NULL;
idx = READLINE_MAX_CMDS - 1;
}
if (new_entry == NULL)
new_entry = strdup(cmdline);
new_entry = g_strdup(cmdline);
rs->history[idx] = new_entry;
rs->hist_entry = -1;
}

View file

@ -225,12 +225,8 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
pstrcpy(slirp->client_hostname, sizeof(slirp->client_hostname),
vhostname);
}
if (tftp_path) {
slirp->tftp_prefix = g_strdup(tftp_path);
}
if (bootfile) {
slirp->bootp_filename = g_strdup(bootfile);
}
slirp->tftp_prefix = g_strdup(tftp_path);
slirp->bootp_filename = g_strdup(bootfile);
slirp->vdhcp_startaddr = vdhcp_start;
slirp->vnameserver_addr = vnameserver;

View file

@ -142,7 +142,9 @@ static void cmos_get_date_time(struct tm *date)
date->tm_mday = mday;
date->tm_mon = mon - 1;
date->tm_year = base_year + year - 1900;
#ifndef __sun__
date->tm_gmtoff = 0;
#endif
ts = mktime(date);
}

View file

@ -115,7 +115,9 @@ static void cmos_get_date_time(struct tm *date)
date->tm_mday = mday;
date->tm_mon = mon - 1;
date->tm_year = base_year + year - 1900;
#ifndef __sun__
date->tm_gmtoff = 0;
#endif
ts = mktime(date);
}

View file

@ -3,7 +3,8 @@
* See the COPYING file in the top-level directory.
*/
#include "ui/qemu-pixman.h"
#include "qemu-common.h"
#include "ui/console.h"
int qemu_pixman_get_type(int rshift, int gshift, int bshift)
{

View file

@ -848,8 +848,8 @@ static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_conn)
int qemu_spice_set_passwd(const char *passwd,
bool fail_if_conn, bool disconnect_if_conn)
{
free(auth_passwd);
auth_passwd = strdup(passwd);
g_free(auth_passwd);
auth_passwd = g_strdup(passwd);
return qemu_spice_set_ticket(fail_if_conn, disconnect_if_conn);
}

View file

@ -120,10 +120,11 @@ static char *vncws_extract_handshake_entry(const char *handshake,
static void vncws_send_handshake_response(VncState *vs, const char* key)
{
char combined_key[WS_CLIENT_KEY_LEN + WS_GUID_LEN + 1];
char hash[SHA1_DIGEST_LEN];
size_t hash_size = SHA1_DIGEST_LEN;
unsigned char hash[SHA1_DIGEST_LEN];
size_t hash_size = sizeof(hash);
char *accept = NULL, *response = NULL;
gnutls_datum_t in;
int ret;
g_strlcpy(combined_key, key, WS_CLIENT_KEY_LEN + 1);
g_strlcat(combined_key, WS_GUID, WS_CLIENT_KEY_LEN + WS_GUID_LEN + 1);
@ -131,9 +132,9 @@ static void vncws_send_handshake_response(VncState *vs, const char* key)
/* hash and encode it */
in.data = (void *)combined_key;
in.size = WS_CLIENT_KEY_LEN + WS_GUID_LEN;
if (gnutls_fingerprint(GNUTLS_DIG_SHA1, &in, hash, &hash_size)
== GNUTLS_E_SUCCESS) {
accept = g_base64_encode((guchar *)hash, SHA1_DIGEST_LEN);
ret = gnutls_fingerprint(GNUTLS_DIG_SHA1, &in, hash, &hash_size);
if (ret == GNUTLS_E_SUCCESS && hash_size <= SHA1_DIGEST_LEN) {
accept = g_base64_encode(hash, hash_size);
}
if (accept == NULL) {
VNC_DEBUG("Hashing Websocket combined key failed\n");

View file

@ -643,9 +643,7 @@ static void opt_set(QemuOpts *opts, const char *name, const char *value,
QTAILQ_INSERT_TAIL(&opts->head, opt, next);
}
opt->desc = desc;
if (value) {
opt->str = g_strdup(value);
}
opt->str = g_strdup(value);
qemu_opt_parse(opt, &local_err);
if (error_is_set(&local_err)) {
error_propagate(errp, local_err);
@ -792,9 +790,7 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
}
}
opts = g_malloc0(sizeof(*opts));
if (id) {
opts->id = g_strdup(id);
}
opts->id = g_strdup(id);
opts->list = list;
loc_save(&opts->loc);
QTAILQ_INIT(&opts->head);