Patchwork [RFC,v1,1/7] memory: fix address space initialization/destruction

login
register
mail settings
Submitter Avi Kivity
Date Oct. 11, 2012, 1:26 p.m.
Message ID <1349962023-560-2-git-send-email-avi@redhat.com>
Download mbox | patch
Permalink /patch/190910/
State New
Headers show

Comments

Avi Kivity - Oct. 11, 2012, 1:26 p.m.
A couple of fields were left uninitialized.  This was not observed earlier
because all address spaces were statically allocated.  Also free allocation
for those fields.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 memory.c | 3 +++
 1 file changed, 3 insertions(+)
Paolo Bonzini - Oct. 11, 2012, 1:31 p.m.
Il 11/10/2012 15:26, Avi Kivity ha scritto:
> A couple of fields were left uninitialized.  This was not observed earlier
> because all address spaces were statically allocated.  Also free allocation
> for those fields.

Patch is obvious, but there are at least two alternatives: 1) using
memset 2) using a compound initializer.

Paolo

> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
>  memory.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/memory.c b/memory.c
> index 2f68d67..5df6177 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1538,6 +1538,8 @@ void address_space_init(AddressSpace *as, MemoryRegion *root)
>      as->root = root;
>      as->current_map = g_new(FlatView, 1);
>      flatview_init(as->current_map);
> +    as->ioeventfd_nb = 0;
> +    as->ioeventfds = NULL;
>      QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link);
>      as->name = NULL;
>      memory_region_transaction_commit();
> @@ -1554,6 +1556,7 @@ void address_space_destroy(AddressSpace *as)
>      address_space_destroy_dispatch(as);
>      flatview_destroy(as->current_map);
>      g_free(as->current_map);
> +    g_free(as->ioeventfds);
>  }
>  
>  uint64_t io_mem_read(MemoryRegion *mr, target_phys_addr_t addr, unsigned size)
>
Avi Kivity - Oct. 11, 2012, 1:33 p.m.
On 10/11/2012 03:31 PM, Paolo Bonzini wrote:
> Il 11/10/2012 15:26, Avi Kivity ha scritto:
>> A couple of fields were left uninitialized.  This was not observed earlier
>> because all address spaces were statically allocated.  Also free allocation
>> for those fields.
> 
> Patch is obvious, but there are at least two alternatives: 1) using
> memset 2) using a compound initializer.

3) std::vector<>, which also covers address_space_destroy().
Blue Swirl - Oct. 13, 2012, 9:14 a.m.
On Thu, Oct 11, 2012 at 1:33 PM, Avi Kivity <avi@redhat.com> wrote:
> On 10/11/2012 03:31 PM, Paolo Bonzini wrote:
>> Il 11/10/2012 15:26, Avi Kivity ha scritto:
>>> A couple of fields were left uninitialized.  This was not observed earlier
>>> because all address spaces were statically allocated.  Also free allocation
>>> for those fields.
>>
>> Patch is obvious, but there are at least two alternatives: 1) using
>> memset 2) using a compound initializer.
>
> 3) std::vector<>, which also covers address_space_destroy().

4) g_malloc0()

>
> --
> error compiling committee.c: too many arguments to function

Patch

diff --git a/memory.c b/memory.c
index 2f68d67..5df6177 100644
--- a/memory.c
+++ b/memory.c
@@ -1538,6 +1538,8 @@  void address_space_init(AddressSpace *as, MemoryRegion *root)
     as->root = root;
     as->current_map = g_new(FlatView, 1);
     flatview_init(as->current_map);
+    as->ioeventfd_nb = 0;
+    as->ioeventfds = NULL;
     QTAILQ_INSERT_TAIL(&address_spaces, as, address_spaces_link);
     as->name = NULL;
     memory_region_transaction_commit();
@@ -1554,6 +1556,7 @@  void address_space_destroy(AddressSpace *as)
     address_space_destroy_dispatch(as);
     flatview_destroy(as->current_map);
     g_free(as->current_map);
+    g_free(as->ioeventfds);
 }
 
 uint64_t io_mem_read(MemoryRegion *mr, target_phys_addr_t addr, unsigned size)