[Spice-devel] [qxl] Xspice: Replace malloc/strdup use with xnfalloc/xnfstrdup

Christophe Fergeau cfergeau at redhat.com
Thu Dec 15 09:57:31 UTC 2016


spiceqxl_*.c files are Xspice-only code. They contain a few uses of
malloc/strdup, and none of these are checked for failure. It's better to
replace these with xfnalloc/xnfstrdup which are provided by the X server
and cannot fail (aborts on failure).

Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
---
 src/spiceqxl_audio.c        |  2 +-
 src/spiceqxl_main_loop.c    |  4 ++--
 src/spiceqxl_spice_server.c | 12 ++++++------
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/spiceqxl_audio.c b/src/spiceqxl_audio.c
index 52a45f0..ec9260d 100644
--- a/src/spiceqxl_audio.c
+++ b/src/spiceqxl_audio.c
@@ -405,7 +405,7 @@ static void handle_one_change(qxl_screen_t *qxl, struct inotify_event *e)
             return;
         }
 
-        fname = malloc(strlen(e->name) + strlen(qxl->playback_fifo_dir) + 1 + 1);
+        fname = xnfalloc(strlen(e->name) + strlen(qxl->playback_fifo_dir) + 1 + 1);
         strcpy(fname, qxl->playback_fifo_dir);
         strcat(fname, "/");
         strcat(fname, e->name);
diff --git a/src/spiceqxl_main_loop.c b/src/spiceqxl_main_loop.c
index c9894bb..669e116 100644
--- a/src/spiceqxl_main_loop.c
+++ b/src/spiceqxl_main_loop.c
@@ -209,7 +209,7 @@ int watch_count = 0;
 
 static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
 {
-    SpiceWatch *watch = malloc(sizeof(SpiceWatch));
+    SpiceWatch *watch = xnfalloc(sizeof(SpiceWatch));
 
     DPRINTF(0, "adding %p, fd=%d at %d", watch,
         fd, watch_count);
@@ -376,7 +376,7 @@ static int watch_update_mask_internal(SpiceWatch *watch, int event_mask)
 
 static SpiceWatch *watch_add(int fd, int event_mask, SpiceWatchFunc func, void *opaque)
 {
-    SpiceWatch *watch = malloc(sizeof(SpiceWatch));
+    SpiceWatch *watch = xnfalloc(sizeof(SpiceWatch));
 
     DPRINTF(0, "adding %p, fd=%d", watch, fd);
 
diff --git a/src/spiceqxl_spice_server.c b/src/spiceqxl_spice_server.c
index 6e8cf50..38257d0 100644
--- a/src/spiceqxl_spice_server.c
+++ b/src/spiceqxl_spice_server.c
@@ -200,23 +200,23 @@ void xspice_set_spice_server_options(OptionInfoPtr options)
         len = strlen(x509_dir) + 32;
 
         if (x509_key_file_base) {
-            x509_key_file = strdup(x509_key_file_base);
+            x509_key_file = xnfstrdup(x509_key_file_base);
         } else {
-            x509_key_file = malloc(len);
+            x509_key_file = xnfalloc(len);
             snprintf(x509_key_file, len, "%s/%s", x509_dir, X509_SERVER_KEY_FILE);
         }
 
         if (x509_cert_file_base) {
-            x509_cert_file = strdup(x509_cert_file_base);
+            x509_cert_file = xnfstrdup(x509_cert_file_base);
         } else {
-            x509_cert_file = malloc(len);
+            x509_cert_file = xnfalloc(len);
             snprintf(x509_cert_file, len, "%s/%s", x509_dir, X509_SERVER_CERT_FILE);
         }
 
         if (x509_cacert_file_base) {
-            x509_cacert_file = strdup(x509_cert_file_base);
+            x509_cacert_file = xnfstrdup(x509_cert_file_base);
         } else {
-            x509_cacert_file = malloc(len);
+            x509_cacert_file = xnfalloc(len);
             snprintf(x509_cacert_file, len, "%s/%s", x509_dir, X509_CA_CERT_FILE);
         }
     }
-- 
2.9.3



More information about the Spice-devel mailing list