Skip to content
Snippets Groups Projects
  1. Aug 20, 2014
    • Markus Armbruster's avatar
      block: Use g_new() & friends to avoid multiplying sizes · 02c4f26b
      Markus Armbruster authored
      
      g_new(T, n) is safer than g_malloc(sizeof(*v) * n) 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.
      
      Perhaps a conversion to g_malloc_n() would be neater in places, but
      that's merely four years old, and we can't use such newfangled stuff.
      
      This commit only touches allocations with size arguments of the form
      sizeof(T), plus two that use 4 instead of sizeof(uint32_t).  We can
      make the others safe by converting to g_malloc_n() when it becomes
      available to us in a couple of years.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      Reviewed-by: default avatarJeff Cody <jcody@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      02c4f26b
    • Markus Armbruster's avatar
      block: Use g_new() & friends where that makes obvious sense · 5839e53b
      Markus Armbruster authored
      
      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.
      
      Patch created with Coccinelle, with two manual changes on top:
      
      * Add const to bdrv_iterate_format() to keep the types straight
      
      * Convert the allocation in bdrv_drop_intermediate(), which Coccinelle
        inexplicably misses
      
      Coccinelle semantic patch:
      
          @@
          type T;
          @@
          -g_malloc(sizeof(T))
          +g_new(T, 1)
          @@
          type T;
          @@
          -g_try_malloc(sizeof(T))
          +g_try_new(T, 1)
          @@
          type T;
          @@
          -g_malloc0(sizeof(T))
          +g_new0(T, 1)
          @@
          type T;
          @@
          -g_try_malloc0(sizeof(T))
          +g_try_new0(T, 1)
          @@
          type T;
          expression n;
          @@
          -g_malloc(sizeof(T) * (n))
          +g_new(T, n)
          @@
          type T;
          expression n;
          @@
          -g_try_malloc(sizeof(T) * (n))
          +g_try_new(T, n)
          @@
          type T;
          expression n;
          @@
          -g_malloc0(sizeof(T) * (n))
          +g_new0(T, n)
          @@
          type T;
          expression n;
          @@
          -g_try_malloc0(sizeof(T) * (n))
          +g_try_new0(T, n)
          @@
          type T;
          expression p, n;
          @@
          -g_realloc(p, sizeof(T) * (n))
          +g_renew(T, p, n)
          @@
          type T;
          expression p, n;
          @@
          -g_try_realloc(p, sizeof(T) * (n))
          +g_try_renew(T, p, n)
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarMax Reitz <mreitz@redhat.com>
      Reviewed-by: default avatarJeff Cody <jcody@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      5839e53b
  2. Aug 19, 2014
    • Peter Maydell's avatar
      Revert "memory: Use canonical path component as the name" · 302fa283
      Peter Maydell authored
      
      This reverts commit b0225c2c
      (which breaks building with Xen enabled and also leaks memory).
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      302fa283
    • Peter Maydell's avatar
      Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging · 0e4a7737
      Peter Maydell authored
      
      SCSI changes that enable sending vendor-specific commands via virtio-scsi.
      
      Memory changes for QOMification and automatic tracking of MR lifetime.
      
      # gpg: Signature made Mon 18 Aug 2014 13:03:09 BST using RSA key ID 9B4D86F2
      # gpg: Good signature from "Paolo Bonzini <pbonzini@redhat.com>"
      # gpg:                 aka "Paolo Bonzini <bonzini@gnu.org>"
      
      * remotes/bonzini/tags/for-upstream:
        mtree: remove write-only field
        memory: Use canonical path component as the name
        memory: Use memory_region_name for name access
        memory: constify memory_region_name
        exec: Abstract away ref to memory region names
        loader: Abstract away ref to memory region names
        tpm_tis: remove instance_finalize callback
        memory: remove memory_region_destroy
        memory: convert memory_region_destroy to object_unparent
        ioport: split deletion and destruction
        nic: do not destroy memory regions in cleanup functions
        vga: do not dynamically allocate chain4_alias
        sysbus: remove unused function sysbus_del_io
        qom: object: move unparenting to the child property's release callback
        qom: object: delete properties before calling instance_finalize
        virtio-scsi: implement parse_cdb
        scsi-block, scsi-generic: implement parse_cdb
        scsi-block: extract scsi_block_is_passthrough
        scsi-bus: introduce parse_cdb in SCSIDeviceClass and SCSIBusInfo
        scsi-bus: prepare scsi_req_new for introduction of parse_cdb
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      0e4a7737
    • Peter Maydell's avatar
      Merge remote-tracking branch 'remotes/qmp-unstable/queue/qmp' into staging · 8e6e2c2a
      Peter Maydell authored
      
      * remotes/qmp-unstable/queue/qmp:
        monitor: fix use after free
        dump.c: Fix memory leak issue in cleanup processing for dump_init()
        monitor: Remove hardcoded watchdog event names
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      8e6e2c2a
  3. Aug 18, 2014
  4. Aug 17, 2014
  5. Aug 15, 2014
Loading