[Spice-commits] 2 commits - server/reds.c server/tests
Frediano Ziglio
fziglio at kemper.freedesktop.org
Wed Mar 1 16:08:42 UTC 2017
server/reds.c | 43 ++++++++++++++++++++++-----------
server/tests/.gitignore | 1
server/tests/Makefile.am | 1
server/tests/test-leaks.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 90 insertions(+), 14 deletions(-)
New commits:
commit f66b7bffc753e7a0e83a3d6835175ffdb04f9867
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Wed Mar 1 11:23:42 2017 +0000
tests: Add basic spice_server_init()/spice_server_destroy()
This can be used for very basic leak checks.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/server/tests/.gitignore b/server/tests/.gitignore
index 0154f32..0c34616 100644
--- a/server/tests/.gitignore
+++ b/server/tests/.gitignore
@@ -23,3 +23,4 @@ test-stream
test-two-servers
test-vdagent
test-gst
+test-leaks
diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index af0bd20..4867d58 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -45,6 +45,7 @@ check_PROGRAMS = \
test-loop \
test-qxl-parsing \
test-stat-file \
+ test-leaks \
$(NULL)
noinst_PROGRAMS = \
diff --git a/server/tests/test-leaks.c b/server/tests/test-leaks.c
new file mode 100644
index 0000000..cd96bc8
--- /dev/null
+++ b/server/tests/test-leaks.c
@@ -0,0 +1,59 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+ Copyright (C) 2017 Red Hat, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#include <config.h>
+#include <glib.h>
+#include <spice.h>
+
+#include "basic-event-loop.h"
+
+/* GLIB_CHECK_VERSION(2, 40, 0) */
+#ifndef g_assert_nonnull
+#define g_assert_nonnull g_assert
+#endif
+
+static void leaks(void)
+{
+ int result;
+ SpiceCoreInterface *core;
+ SpiceServer *server = spice_server_new();
+
+ g_assert_nonnull(server);
+
+ core = basic_event_loop_init();
+ g_assert_nonnull(core);
+
+ g_assert_cmpint(spice_server_init(server, core), ==, 0);
+
+ /* cause the allocation of spice name */
+ spice_server_set_name(server, "Test Spice Name");
+
+ /* cause the allocation of security options */
+ result = spice_server_set_channel_security(server, "main", SPICE_CHANNEL_SECURITY_SSL);
+ g_assert_cmpint(result, ==, 0);
+
+ spice_server_destroy(server);
+}
+
+int main(int argc, char *argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/server/server leaks", leaks);
+
+ return g_test_run();
+}
commit a6f7aeb5d869dcdf4217f23e3e99f240d9415d05
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Tue Feb 28 23:26:07 2017 +0000
reds: Free remaining configuration
Free security, migration, sasl and name stuff.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
diff --git a/server/reds.c b/server/reds.c
index 898be92..a28653c 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -2909,13 +2909,13 @@ static void reds_set_one_channel_security(RedsState *reds, int id, uint32_t secu
#define REDS_SAVE_VERSION 1
-static void reds_mig_release(RedsState *reds)
+static void reds_mig_release(RedServerConfig *config)
{
- if (reds->config->mig_spice) {
- free(reds->config->mig_spice->cert_subject);
- free(reds->config->mig_spice->host);
- free(reds->config->mig_spice);
- reds->config->mig_spice = NULL;
+ if (config->mig_spice) {
+ free(config->mig_spice->cert_subject);
+ free(config->mig_spice->host);
+ free(config->mig_spice);
+ config->mig_spice = NULL;
}
}
@@ -2987,7 +2987,7 @@ static void reds_mig_finished(RedsState *reds, int completed)
} else {
reds_mig_cleanup(reds);
}
- reds_mig_release(reds);
+ reds_mig_release(reds->config);
}
static void reds_mig_switch(RedsState *reds)
@@ -2997,7 +2997,7 @@ static void reds_mig_switch(RedsState *reds)
return;
}
main_channel_migrate_switch(reds->main_channel, reds->config->mig_spice);
- reds_mig_release(reds);
+ reds_mig_release(reds->config);
}
static void migrate_timeout(void *opaque)
@@ -3640,6 +3640,24 @@ SPICE_GNUC_VISIBLE int spice_server_init(SpiceServer *reds, SpiceCoreInterface *
return ret;
}
+static void reds_config_free(RedServerConfig *config)
+{
+ ChannelSecurityOptions *curr, *next;
+
+ reds_mig_release(config);
+ for (curr = config->channels_security; curr; curr = next) {
+ next = curr->next;
+ free(curr);
+ }
+#if HAVE_SASL
+ free(config->sasl_appname);
+#endif
+ free(config->spice_name);
+ g_array_unref(config->renderers);
+ g_array_unref(config->video_codecs);
+ free(config);
+}
+
SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer *reds)
{
/* remove the server from the list of servers so that we don't attempt to
@@ -3668,10 +3686,7 @@ SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer *reds)
stat_file_free(reds->stat_file);
#endif
- g_array_unref(reds->config->renderers);
- g_array_unref(reds->config->video_codecs);
- free(reds->config);
-
+ reds_config_free(reds->config);
free(reds);
}
@@ -4019,7 +4034,7 @@ static int reds_set_migration_dest_info(RedsState *reds,
{
RedsMigSpice *spice_migration = NULL;
- reds_mig_release(reds);
+ reds_mig_release(reds->config);
if ((port == -1 && secure_port == -1) || !dest) {
return FALSE;
}
@@ -4079,7 +4094,7 @@ SPICE_GNUC_VISIBLE int spice_server_migrate_connect(SpiceServer *reds, const cha
reds_mig_started(reds);
} else {
if (reds->clients == NULL) {
- reds_mig_release(reds);
+ reds_mig_release(reds->config);
spice_info("no client connected");
}
sif->migrate_connect_complete(reds->migration_interface);
More information about the Spice-commits
mailing list