[libvirt] [PATCH 1/4] Fix const correctness

Michal Privoznik mprivozn at redhat.com
Tue Jul 15 12:38:33 UTC 2014


In many places we define a variable as a 'const char *' when in fact
we modify it just a few lines below. Or even free it. We should not do
that.

There's one exception though, in xenSessionFree() xenapi_utils.c. We
are freeing the xen_session structure which is defined in
xen/api/xen_common.h public header. The structure contains session_id
which is type of 'const char *' when in fact it should have been just
'char *'. So I'm leaving this unmodified, just noticing the fact in
comment.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 src/locking/lock_driver_lockd.c      | 2 +-
 src/qemu/qemu_capabilities.c         | 2 +-
 src/remote/remote_driver.c           | 2 +-
 src/xenapi/xenapi_utils.c            | 1 +
 tools/virsh-domain.c                 | 4 ++--
 tools/wireshark/src/packet-libvirt.c | 6 +++---
 tools/wireshark/src/packet-libvirt.h | 4 ++--
 7 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/locking/lock_driver_lockd.c b/src/locking/lock_driver_lockd.c
index 1ca7772..367d0ce 100644
--- a/src/locking/lock_driver_lockd.c
+++ b/src/locking/lock_driver_lockd.c
@@ -243,7 +243,7 @@ static virNetClientPtr virLockManagerLockDaemonConnectionNew(bool privileged,
 {
     virNetClientPtr client = NULL;
     char *lockdpath;
-    const char *daemonPath = NULL;
+    char *daemonPath = NULL;
 
     *prog = NULL;
 
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 37e0588..8271e28 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2652,7 +2652,7 @@ static int
 virQEMUCapsSaveCache(virQEMUCapsPtr qemuCaps, const char *filename)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
-    const char *xml = NULL;
+    char *xml = NULL;
     int ret = -1;
     size_t i;
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 9d8120f..9a1d78f 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -582,7 +582,7 @@ doRemoteOpen(virConnectPtr conn,
         trans_tcp,
     } transport;
 #ifndef WIN32
-    const char *daemonPath = NULL;
+    char *daemonPath = NULL;
 #endif
 
     /* We handle *ALL* URIs here. The caller has rejected any
diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c
index 8b28914..a80d136 100644
--- a/src/xenapi/xenapi_utils.c
+++ b/src/xenapi/xenapi_utils.c
@@ -49,6 +49,7 @@ xenSessionFree(xen_session *session)
             VIR_FREE(session->error_description[i]);
         VIR_FREE(session->error_description);
     }
+    /* The session_id member is type of 'const char *'. Sigh. */
     VIR_FREE(session->session_id);
     VIR_FREE(session);
 }
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 5a17aff..ba47258 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10349,8 +10349,8 @@ vshPrepareDiskXML(xmlNodePtr disk_node,
                   int type)
 {
     xmlNodePtr cur = NULL;
-    const char *disk_type = NULL;
-    const char *device_type = NULL;
+    char *disk_type = NULL;
+    char *device_type = NULL;
     xmlNodePtr new_node = NULL;
     char *ret = NULL;
 
diff --git a/tools/wireshark/src/packet-libvirt.c b/tools/wireshark/src/packet-libvirt.c
index 0fe5f03..5c3c369 100644
--- a/tools/wireshark/src/packet-libvirt.c
+++ b/tools/wireshark/src/packet-libvirt.c
@@ -105,7 +105,7 @@ dissect_xdr_string(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf,
     }
 }
 
-static gchar *
+static const gchar *
 format_xdr_bytes(guint8 *bytes, guint32 length)
 {
     gchar *buf;
@@ -206,7 +206,7 @@ dissect_xdr_iterable(tvbuff_t *tvb, proto_item *ti, XDR *xdrs, gint ett, int rhf
 
 static gboolean
 dissect_xdr_vector(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, gint ett,
-                   int rhf, gchar *rtype, guint32 size, vir_xdr_dissector_t dissect)
+                   int rhf, const gchar *rtype, guint32 size, vir_xdr_dissector_t dissect)
 {
     goffset start;
     proto_item *ti;
@@ -219,7 +219,7 @@ dissect_xdr_vector(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, gint ett,
 
 static gboolean
 dissect_xdr_array(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, gint ett,
-                  int rhf, gchar *rtype, guint32 maxlen, vir_xdr_dissector_t dissect)
+                  int rhf, const gchar *rtype, guint32 maxlen, vir_xdr_dissector_t dissect)
 {
     goffset start;
     proto_item *ti;
diff --git a/tools/wireshark/src/packet-libvirt.h b/tools/wireshark/src/packet-libvirt.h
index af54407..5f99fdf 100644
--- a/tools/wireshark/src/packet-libvirt.h
+++ b/tools/wireshark/src/packet-libvirt.h
@@ -105,9 +105,9 @@ static gboolean dissect_xdr_bytes(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, in
 static gboolean dissect_xdr_pointer(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf,
                                     vir_xdr_dissector_t dp);
 static gboolean dissect_xdr_vector(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, gint ett,
-                                   int rhf, gchar *rtype, guint32 size, vir_xdr_dissector_t dp);
+                                   int rhf, const gchar *rtype, guint32 size, vir_xdr_dissector_t dp);
 static gboolean dissect_xdr_array(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, gint ett,
-                                  int rhf, gchar *rtype, guint32 maxlen, vir_xdr_dissector_t dp);
+                                  int rhf, const gchar *rtype, guint32 maxlen, vir_xdr_dissector_t dp);
 
 # include "libvirt/protocol.h"
 
-- 
1.8.5.5




More information about the libvir-list mailing list