[libvirt] [PATCH v4 2/3] interface: Consume @def in virInterfaceObjNew

John Ferlan posted 3 patches 8 years, 6 months ago
[libvirt] [PATCH v4 2/3] interface: Consume @def in virInterfaceObjNew
Posted by John Ferlan 8 years, 6 months ago
Move the consumption of @def in virInterfaceObjNew and then handle that
in the error path of virInterfaceObjListAssignDef since it's caller expects
to need to free @def when NULL is returned and so would virInterfaceObjFree.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/conf/virinterfaceobj.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index 1e3f25c..159fcb2 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -47,7 +47,7 @@ struct _virInterfaceObjList {
 /* virInterfaceObj manipulation */
 
 static virInterfaceObjPtr
-virInterfaceObjNew(void)
+virInterfaceObjNew(virInterfaceDefPtr def)
 {
     virInterfaceObjPtr obj;
 
@@ -62,6 +62,7 @@ virInterfaceObjNew(void)
     }
 
     virInterfaceObjLock(obj);
+    obj->def = def;
 
     return obj;
 }
@@ -251,17 +252,17 @@ virInterfaceObjListAssignDef(virInterfaceObjListPtr interfaces,
         return obj;
     }
 
-    if (!(obj = virInterfaceObjNew()))
+    if (!(obj = virInterfaceObjNew(def)))
         return NULL;
 
     if (VIR_APPEND_ELEMENT_COPY(interfaces->objs,
                                 interfaces->count, obj) < 0) {
+        obj->def = NULL;
         virInterfaceObjUnlock(obj);
         virInterfaceObjFree(obj);
         return NULL;
     }
 
-    obj->def = def;
     return obj;
 
 }
-- 
2.9.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 2/3] interface: Consume @def in virInterfaceObjNew
Posted by Erik Skultety 8 years, 6 months ago
On Sat, Jun 03, 2017 at 06:53:22AM -0400, John Ferlan wrote:
> Move the consumption of @def in virInterfaceObjNew and then handle that
> in the error path of virInterfaceObjListAssignDef since it's caller expects
> to need to free @def when NULL is returned and so would virInterfaceObjFree.
>
> Signed-off-by: John Ferlan <jferlan@redhat.com>
> ---
>  src/conf/virinterfaceobj.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
> index 1e3f25c..159fcb2 100644
> --- a/src/conf/virinterfaceobj.c
> +++ b/src/conf/virinterfaceobj.c
> @@ -47,7 +47,7 @@ struct _virInterfaceObjList {
>  /* virInterfaceObj manipulation */
>
>  static virInterfaceObjPtr
> -virInterfaceObjNew(void)
> +virInterfaceObjNew(virInterfaceDefPtr def)
>  {
>      virInterfaceObjPtr obj;
>
> @@ -62,6 +62,7 @@ virInterfaceObjNew(void)
>      }
>
>      virInterfaceObjLock(obj);
> +    obj->def = def;

I'd probably move this before locking the object, first initializing it and
then locking and returning it, but that's a matter of preference.

ACK.
Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list