merge branch 'th/memleaks-nm-1-0' into nm-1-0

Backport several memleak fixes from master and enable
VALGRIND for most tests.

With valgrind enabled, I get sometimes non-reproducible failures
in src/tests/test-general-with-expect (monotonic_timestamp_get())
and libnm/tests/test-nm-client.c:911.

Still, merge it to have tests enabled in the first place. Possibly
fix them later.

https://mail.gnome.org/archives/networkmanager-list/2015-March/msg00041.html
This commit is contained in:
Thomas Haller 2015-03-13 11:51:58 +01:00
commit 050301d4d7
71 changed files with 683 additions and 205 deletions

View file

@ -28,6 +28,7 @@ test_dispatcher_envp_LDADD = \
###########################################
@VALGRIND_RULES@
TESTS = test-dispatcher-envp
endif

View file

@ -204,12 +204,12 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
split = g_strsplit_set (tmp, " ", -1);
g_free (tmp);
if (g_strv_length (split) > 0) {
if (split && g_strv_length (split) > 0) {
for (iter = split; iter && *iter; iter++)
g_strstrip (*iter);
g_variant_builder_add (&props, "{sv}", "domains", g_variant_new_strv ((gpointer) split, -1));
g_strfreev (split);
}
g_strfreev (split);
/* nameservers */
if (!add_uint_array (kf, &props, "ip4", "nameservers", error))
@ -225,7 +225,7 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
split = g_strsplit_set (tmp, ",", -1);
g_free (tmp);
if (g_strv_length (split) > 0) {
if (split && g_strv_length (split) > 0) {
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
for (iter = split; iter && *iter; iter++) {
NMIPAddress *addr;
@ -267,7 +267,7 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
split = g_strsplit_set (tmp, ",", -1);
g_free (tmp);
if (g_strv_length (split) > 0) {
if (split && g_strv_length (split) > 0) {
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
for (iter = split; iter && *iter; iter++) {
NMIPRoute *route;
@ -328,11 +328,15 @@ parse_dhcp (GKeyFile *kf,
g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
for (iter = keys; iter && *iter; iter++) {
val = g_key_file_get_string (kf, group_name, *iter, error);
if (!val)
if (!val) {
g_strfreev (keys);
g_variant_builder_clear (&props);
return FALSE;
}
g_variant_builder_add (&props, "{sv}", *iter, g_variant_new_string (val));
g_free (val);
}
g_strfreev (keys);
*out_props = g_variant_builder_end (&props);
return TRUE;
@ -359,6 +363,21 @@ get_dispatcher_file (const char *file,
gboolean success = FALSE;
char **keys, **iter, *val;
g_assert (!error || !*error);
g_assert (out_con_dict && !*out_con_dict);
g_assert (out_con_props && !*out_con_props);
g_assert (out_device_props && !*out_device_props);
g_assert (out_device_ip4_props && !*out_device_ip4_props);
g_assert (out_device_ip6_props && !*out_device_ip6_props);
g_assert (out_device_dhcp4_props && !*out_device_dhcp4_props);
g_assert (out_device_dhcp6_props && !*out_device_dhcp6_props);
g_assert (out_vpn_ip_iface && !*out_vpn_ip_iface);
g_assert (out_vpn_ip4_props && !*out_vpn_ip4_props);
g_assert (out_vpn_ip6_props && !*out_vpn_ip6_props);
g_assert (out_expected_iface && !*out_expected_iface);
g_assert (out_action && !*out_action);
g_assert (out_env && !*out_env);
kf = g_key_file_new ();
if (!g_key_file_load_from_file (kf, file, G_KEY_FILE_NONE, error))
return FALSE;
@ -512,6 +531,7 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
g_assert_cmpstr (expected_iface, ==, out_iface);
g_strfreev (denv);
g_free (out_iface);
g_free (vpn_ip_iface);
g_free (expected_iface);

View file

@ -6488,6 +6488,7 @@ nmc_setting_get_valid_properties (NMSetting *setting)
valid_props[i++] = g_strdup (key_name);
}
valid_props[i] = NULL;
g_free (props);
return valid_props;
}

View file

@ -855,6 +855,7 @@ AM_CONDITIONAL(REQUIRE_ROOT_TESTS, test "$enable_tests" == "root")
AS_IF([test "$with_valgrind" != "no"],
AC_SUBST(VALGRIND_RULES, 'TESTS_ENVIRONMENT = "$(top_srcdir)/tools/run-test-valgrind.sh" "$(LIBTOOL)" "$(with_valgrind)" "$(top_srcdir)/valgrind.suppressions"'),
AC_SUBST(VALGRIND_RULES, []))
AM_CONDITIONAL(WITH_VALGRIND, test "${with_valgrind}" != "no")
GTK_DOC_CHECK(1.0)

View file

@ -1065,8 +1065,8 @@ typedef enum {
g_variant_builder_add (&__setting_builder, "{sv}", \
__cur_property_name, \
__property_val); \
} else \
g_variant_unref (__property_val); \
} \
g_variant_unref (__property_val); \
} \
\
if (__cur_setting_name) \

View file

@ -100,4 +100,64 @@
_found; \
})
/*****************************************************************************/
#define NM_DEFINE_SINGLETON_INSTANCE(TYPE) \
static TYPE *singleton_instance
#define NM_DEFINE_SINGLETON_WEAK_REF(TYPE) \
NM_DEFINE_SINGLETON_INSTANCE (TYPE); \
static void \
_singleton_instance_weak_ref_cb (gpointer data, \
GObject *where_the_object_was) \
{ \
nm_log_dbg (LOGD_CORE, "disposing %s singleton (%p)", G_STRINGIFY (TYPE), singleton_instance); \
singleton_instance = NULL; \
} \
static inline void \
nm_singleton_instance_weak_ref_register (void) \
{ \
g_object_weak_ref (G_OBJECT (singleton_instance), _singleton_instance_weak_ref_cb, NULL); \
}
#define NM_DEFINE_SINGLETON_DESTRUCTOR(TYPE) \
NM_DEFINE_SINGLETON_INSTANCE (TYPE); \
static void __attribute__((destructor)) \
_singleton_destructor (void) \
{ \
if (singleton_instance) { \
if (G_OBJECT (singleton_instance)->ref_count > 1) \
nm_log_dbg (LOGD_CORE, "disown %s singleton (%p)", G_STRINGIFY (TYPE), singleton_instance); \
g_object_unref (singleton_instance); \
} \
}
/* By default, the getter will assert that the singleton will be created only once. You can
* change this by redefining NM_DEFINE_SINGLETON_ALLOW_MULTIPLE. */
#ifndef NM_DEFINE_SINGLETON_ALLOW_MULTIPLE
#define NM_DEFINE_SINGLETON_ALLOW_MULTIPLE FALSE
#endif
#define NM_DEFINE_SINGLETON_GETTER(TYPE, GETTER, GTYPE, ...) \
NM_DEFINE_SINGLETON_INSTANCE (TYPE); \
NM_DEFINE_SINGLETON_WEAK_REF (TYPE); \
TYPE * \
GETTER (void) \
{ \
if (G_UNLIKELY (!singleton_instance)) { \
static char _already_created = FALSE; \
\
g_assert (!_already_created || (NM_DEFINE_SINGLETON_ALLOW_MULTIPLE)); \
_already_created = TRUE;\
singleton_instance = (g_object_new (GTYPE, ##__VA_ARGS__, NULL)); \
g_assert (singleton_instance); \
nm_singleton_instance_weak_ref_register (); \
nm_log_dbg (LOGD_CORE, "create %s singleton (%p)", G_STRINGIFY (TYPE), singleton_instance); \
} \
return singleton_instance; \
} \
NM_DEFINE_SINGLETON_DESTRUCTOR(TYPE)
/*****************************************************************************/
#endif

View file

@ -304,6 +304,8 @@ nm_connection_replace_settings (NMConnection *connection,
for (s = settings; s; s = s->next)
_nm_connection_add_setting (connection, s->data);
g_slist_free (settings);
if (changed)
g_signal_emit (connection, signals[CHANGED], 0);
return TRUE;

View file

@ -1884,6 +1884,7 @@ nm_setting_802_1x_get_private_key_format (NMSetting8021x *setting)
g_error_free (error);
return NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
}
g_error_free (error);
return NM_SETTING_802_1X_CK_FORMAT_RAW_KEY;
default:
break;
@ -2164,6 +2165,7 @@ nm_setting_802_1x_get_phase2_private_key_format (NMSetting8021x *setting)
g_error_free (error);
return NM_SETTING_802_1X_CK_FORMAT_UNKNOWN;
}
g_error_free (error);
return NM_SETTING_802_1X_CK_FORMAT_RAW_KEY;
default:
break;

View file

@ -968,8 +968,9 @@ find_virtual_interface_name (GVariant *connection_dict)
/* All of the deprecated virtual interface name properties were named "interface-name". */
if (!g_variant_lookup (setting_dict, "interface-name", "&s", &interface_name))
return NULL;
interface_name = NULL;
g_variant_unref (setting_dict);
return interface_name;
}

View file

@ -50,7 +50,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_DCB)
typedef struct {
NMSettingDcbFlags app_fcoe_flags;
gint app_fcoe_priority;
const char * app_fcoe_mode;
char * app_fcoe_mode;
NMSettingDcbFlags app_iscsi_flags;
gint app_iscsi_priority;
@ -793,6 +793,7 @@ set_property (GObject *object, guint prop_id,
priv->app_fcoe_priority = g_value_get_int (value);
break;
case PROP_APP_FCOE_MODE:
g_free (priv->app_fcoe_mode);
priv->app_fcoe_mode = g_value_dup_string (value);
break;
case PROP_APP_ISCSI_FLAGS:
@ -896,6 +897,16 @@ get_property (GObject *object, guint prop_id,
}
}
static void
finalize (GObject *object)
{
NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (object);
g_free (priv->app_fcoe_mode);
G_OBJECT_CLASS (nm_setting_dcb_parent_class)->finalize (object);
}
static void
nm_setting_dcb_class_init (NMSettingDcbClass *setting_class)
{
@ -907,6 +918,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *setting_class)
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
/* Properties */

View file

@ -130,6 +130,7 @@ set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_CONFIG:
g_free (priv->config);
priv->config = g_value_dup_string (value);
break;
default:
@ -154,6 +155,16 @@ get_property (GObject *object, guint prop_id,
}
}
static void
finalize (GObject *object)
{
NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (object);
g_free (priv->config);
G_OBJECT_CLASS (nm_setting_team_port_parent_class)->finalize (object);
}
static void
nm_setting_team_port_class_init (NMSettingTeamPortClass *setting_class)
{
@ -165,6 +176,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *setting_class)
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
/* Properties */

View file

@ -434,27 +434,24 @@ nm_setting_wired_get_s390_option (NMSettingWired *setting,
const char **out_key,
const char **out_value)
{
NMSettingWiredPrivate *priv;
guint32 num_keys;
GList *keys;
const char *_key = NULL, *_value = NULL;
const char *_key, *_value;
GHashTableIter iter;
guint i = 0;
g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
num_keys = nm_setting_wired_get_num_s390_options (setting);
g_return_val_if_fail (idx < num_keys, FALSE);
keys = g_hash_table_get_keys (priv->s390_options);
_key = g_list_nth_data (keys, idx);
_value = g_hash_table_lookup (priv->s390_options, _key);
if (out_key)
*out_key = _key;
if (out_value)
*out_value = _value;
return TRUE;
g_hash_table_iter_init (&iter, NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options);
while (g_hash_table_iter_next (&iter, (gpointer) &_key, (gpointer) &_value)) {
if (i == idx) {
if (out_key)
*out_key = _key;
if (out_value)
*out_value = _value;
return TRUE;
}
i++;
}
g_return_val_if_reached (FALSE);
}
/**

View file

@ -1802,6 +1802,7 @@ nm_utils_ip_addresses_from_variant (GVariant *value,
g_variant_unref (attr_val);
}
g_variant_unref (addr_var);
g_ptr_array_add (addresses, addr);
}

View file

@ -24,6 +24,7 @@ LDADD = \
$(top_builddir)/libnm-core/libnm-core.la \
$(GLIB_LIBS)
@VALGRIND_RULES@
TESTS = $(noinst_PROGRAMS)
endif

View file

@ -98,7 +98,7 @@ out:
static void
test_cert (gconstpointer test_data)
{
char *path;
gs_free char *path = NULL;
GByteArray *array;
NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
GError *error = NULL;
@ -226,6 +226,7 @@ test_is_pkcs12 (const char *path, gboolean expect_fail)
if (expect_fail) {
g_assert_error (error, NM_CRYPTO_ERROR, NM_CRYPTO_ERROR_INVALID_DATA);
g_assert (!is_pkcs12);
g_clear_error (&error);
} else {
g_assert_no_error (error);
g_assert (is_pkcs12);

View file

@ -25,6 +25,7 @@
#include <string.h>
#include <nm-utils.h>
#include "gsystem-local-alloc.h"
#include "nm-setting-private.h"
#include "nm-utils.h"
@ -648,7 +649,7 @@ test_setting_ip4_config_address_data (void)
static void
test_setting_gsm_apn_spaces (void)
{
NMSettingGsm *s_gsm;
gs_unref_object NMSettingGsm *s_gsm = NULL;
const char *tmp;
s_gsm = (NMSettingGsm *) nm_setting_gsm_new ();
@ -676,7 +677,7 @@ test_setting_gsm_apn_spaces (void)
static void
test_setting_gsm_apn_bad_chars (void)
{
NMSettingGsm *s_gsm;
gs_unref_object NMSettingGsm *s_gsm = NULL;
s_gsm = (NMSettingGsm *) nm_setting_gsm_new ();
ASSERT (s_gsm != NULL,
@ -714,7 +715,7 @@ test_setting_gsm_apn_bad_chars (void)
static void
test_setting_gsm_apn_underscore (void)
{
NMSettingGsm *s_gsm;
gs_unref_object NMSettingGsm *s_gsm = NULL;
s_gsm = (NMSettingGsm *) nm_setting_gsm_new ();
g_assert (s_gsm);
@ -729,7 +730,7 @@ test_setting_gsm_apn_underscore (void)
static void
test_setting_gsm_without_number (void)
{
NMSettingGsm *s_gsm;
gs_unref_object NMSettingGsm *s_gsm = NULL;
s_gsm = (NMSettingGsm *) nm_setting_gsm_new ();
g_assert (s_gsm);
@ -1551,6 +1552,7 @@ test_connection_replace_settings_bad (void)
connection = new_test_connection ();
success = nm_connection_replace_settings (connection, new_settings, &error);
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_SETTING);
g_clear_error (&error);
g_assert (!success);
g_assert (nm_connection_verify (connection, NULL));
@ -2388,7 +2390,7 @@ test_connection_bad_base_types (void)
static void
test_setting_compare_id (void)
{
NMSetting *old, *new;
gs_unref_object NMSetting *old = NULL, *new = NULL;
gboolean success;
old = nm_setting_connection_new ();
@ -2412,7 +2414,7 @@ test_setting_compare_id (void)
static void
test_setting_compare_timestamp (void)
{
NMSetting *old, *new;
gs_unref_object NMSetting *old = NULL, *new = NULL;
gboolean success;
old = nm_setting_connection_new ();
@ -2457,7 +2459,7 @@ static void
test_setting_compare_secrets (gconstpointer test_data)
{
const TestDataCompareSecrets *data = test_data;
NMSetting *old, *new;
gs_unref_object NMSetting *old = NULL, *new = NULL;
gboolean success;
/* Make sure that a connection with transient/unsaved secrets compares
@ -2488,7 +2490,7 @@ static void
test_setting_compare_vpn_secrets (gconstpointer test_data)
{
const TestDataCompareSecrets *data = test_data;
NMSetting *old, *new;
gs_unref_object NMSetting *old = NULL, *new = NULL;
gboolean success;
/* Make sure that a connection with transient/unsaved secrets compares
@ -2764,7 +2766,7 @@ test_setting_connection_changed_signal (void)
NMConnection *connection;
gboolean changed = FALSE;
NMSettingConnection *s_con;
char *uuid;
gs_free char *uuid = NULL;
connection = nm_simple_connection_new ();
g_signal_connect (connection,
@ -3170,7 +3172,7 @@ test_setting_802_1x_changed_signal (void)
static void
test_setting_old_uuid (void)
{
NMSetting *setting;
gs_unref_object NMSetting *setting = NULL;
/* NetworkManager-0.9.4.0 generated 40-character UUIDs with no dashes,
* like this one. Test that we maintain compatibility. */
@ -3879,6 +3881,7 @@ test_setting_ip6_gateway (void)
value = g_variant_lookup_value (ip6_dict, NM_SETTING_IP_CONFIG_GATEWAY, G_VARIANT_TYPE_STRING);
g_assert (value != NULL);
g_assert_cmpstr (g_variant_get_string (value, NULL), ==, "abcd::1");
g_variant_unref (value);
value = g_variant_lookup_value (ip6_dict, NM_SETTING_IP_CONFIG_ADDRESSES, G_VARIANT_TYPE ("a(ayuay)"));
g_assert (value != NULL);
@ -3975,6 +3978,7 @@ test_hexstr2bin (void)
g_assert (b);
g_assert_cmpint (g_bytes_get_size (b), ==, items[i].expected_len);
g_assert (memcmp (g_bytes_get_data (b, NULL), items[i].expected, g_bytes_get_size (b)) == 0);
g_bytes_unref (b);
} else
g_assert (b == NULL);
}

View file

@ -176,6 +176,7 @@ test_need_tls_secrets_path (void)
"need-tls-secrets-path-key-password",
"expected to require private key password, but it wasn't");
g_ptr_array_free (hints, TRUE);
g_object_unref (connection);
}
@ -219,6 +220,7 @@ test_need_tls_secrets_blob (void)
"need-tls-secrets-blob-key-password",
"expected to require private key password, but it wasn't");
g_ptr_array_free (hints, TRUE);
g_object_unref (connection);
}
@ -345,6 +347,7 @@ test_need_tls_phase2_secrets_path (void)
"need-tls-phase2-secrets-path-key-password",
"expected to require private key password, but it wasn't");
g_ptr_array_free (hints, TRUE);
g_object_unref (connection);
}
@ -389,6 +392,7 @@ test_need_tls_phase2_secrets_blob (void)
"need-tls-phase2-secrets-blob-key-password",
"expected to require private key password, but it wasn't");
g_ptr_array_free (hints, TRUE);
g_object_unref (connection);
}
@ -559,8 +563,8 @@ test_update_secrets_wifi_bad_setting_name (void)
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND);
g_assert (success == FALSE);
g_clear_error (&error);
g_variant_unref (secrets);
g_object_unref (connection);
}
@ -668,6 +672,7 @@ test_update_secrets_whole_connection_bad_setting (void)
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND);
g_assert (success == FALSE);
g_clear_error (&error);
g_variant_unref (copy);
g_object_unref (connection);
}

View file

@ -186,6 +186,7 @@ test_phase2_private_key_import (const char *path,
g_object_get (s_8021x, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, &tmp_key, NULL);
ASSERT (tmp_key != NULL, "phase2-private-key-import", "missing private key value");
check_scheme_path (tmp_key, path);
g_bytes_unref (tmp_key);
} else
g_assert_not_reached ();
@ -245,6 +246,7 @@ test_wrong_password_keeps_data (const char *path, const char *password)
"wrong-password-keeps-data", "unexpected missing error");
ASSERT (format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"wrong-password-keeps-data", "unexpected success reading private key format");
g_clear_error (&error);
/* Make sure the password hasn't changed */
pw = nm_setting_802_1x_get_private_key_password (s_8021x);
@ -342,6 +344,7 @@ test_wrong_phase2_password_keeps_data (const char *path, const char *password)
"wrong-phase2-password-keeps-data", "unexpected missing error");
ASSERT (format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"wrong-phase2-password-keeps-data", "unexpected success reading private key format");
g_clear_error (&error);
/* Make sure the password hasn't changed */
pw = nm_setting_802_1x_get_phase2_private_key_password (s_8021x);

View file

@ -28,6 +28,7 @@
#include "nm-setting-dcb.h"
#include "nm-connection.h"
#include "nm-errors.h"
#include "gsystem-local-alloc.h"
#define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
NM_SETTING_DCB_FLAG_ADVERTISE | \
@ -36,7 +37,7 @@
static void
test_dcb_flags_valid (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;
guint i;
@ -89,7 +90,7 @@ test_dcb_flags_valid (void)
static void
test_dcb_flags_invalid (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;
@ -148,7 +149,7 @@ test_dcb_flags_invalid (void)
static void
test_dcb_app_priorities (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;
@ -210,7 +211,7 @@ test_dcb_app_priorities (void)
static void
test_dcb_priorities_valid (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;
guint i;
@ -269,7 +270,7 @@ test_dcb_priorities_valid (void)
static void
test_dcb_bandwidth_sums (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;

View file

@ -12,6 +12,11 @@ AM_CPPFLAGS = \
noinst_PROGRAMS = $(TESTS)
if WITH_VALGRIND
@VALGRIND_RULES@ --launch-dbus
else
TESTS_ENVIRONMENT = $(srcdir)/libnm-glib-test-launch.sh
endif
TESTS = test-nm-client test-remote-settings-client
####### NMClient and non-settings tests #######
@ -42,8 +47,6 @@ test_remote_settings_client_LDADD = \
###########################################
TESTS_ENVIRONMENT = $(srcdir)/libnm-glib-test-launch.sh
endif
EXTRA_DIST = libnm-glib-test-launch.sh

View file

@ -36,6 +36,7 @@
#include "nm-remote-settings.h"
#include "common.h"
#include "gsystem-local-alloc.h"
static NMTestServiceInfo *sinfo;
static NMRemoteSettings *settings = NULL;
@ -63,7 +64,7 @@ add_cb (NMRemoteSettings *s,
static void
test_add_connection (void)
{
NMConnection *connection;
gs_unref_object NMConnection *connection = NULL;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
char *uuid;
@ -256,6 +257,7 @@ test_make_visible (void)
break;
}
}
g_slist_free (list);
g_assert (found == TRUE);
g_free (path);
@ -298,6 +300,7 @@ test_remove_connection (void)
g_assert_cmpint (g_slist_length (list), >, 0);
connection = NM_REMOTE_CONNECTION (list->data);
g_slist_free (list);
g_assert (connection);
g_assert (remote == connection);
path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
@ -329,6 +332,7 @@ test_remove_connection (void)
g_assert ((gpointer) connection != (gpointer) candidate);
g_assert_cmpstr (path, ==, nm_connection_get_path (candidate));
}
g_slist_free (list);
g_free (path);
g_object_unref (proxy);

View file

@ -1241,7 +1241,7 @@ nm_connection_to_hash (NMConnection *connection, NMSettingHashFlags flags)
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
ret = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) g_hash_table_destroy);
g_free, (GDestroyNotify) g_hash_table_unref);
priv = NM_CONNECTION_GET_PRIVATE (connection);

View file

@ -78,7 +78,7 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_DCB)
typedef struct {
NMSettingDcbFlags app_fcoe_flags;
gint app_fcoe_priority;
const char * app_fcoe_mode;
char * app_fcoe_mode;
NMSettingDcbFlags app_iscsi_flags;
gint app_iscsi_priority;
@ -833,6 +833,7 @@ set_property (GObject *object, guint prop_id,
priv->app_fcoe_priority = g_value_get_int (value);
break;
case PROP_APP_FCOE_MODE:
g_free (priv->app_fcoe_mode);
priv->app_fcoe_mode = g_value_dup_string (value);
break;
case PROP_APP_ISCSI_FLAGS:
@ -944,6 +945,16 @@ get_property (GObject *object, guint prop_id,
}
}
static void
finalize (GObject *object)
{
NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (object);
g_free (priv->app_fcoe_mode);
G_OBJECT_CLASS (nm_setting_dcb_parent_class)->finalize (object);
}
static void
nm_setting_dcb_class_init (NMSettingDcbClass *setting_class)
{
@ -955,6 +966,7 @@ nm_setting_dcb_class_init (NMSettingDcbClass *setting_class)
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
/* Properties */

View file

@ -130,6 +130,7 @@ set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_CONFIG:
g_free (priv->config);
priv->config = g_value_dup_string (value);
break;
default:
@ -154,6 +155,16 @@ get_property (GObject *object, guint prop_id,
}
}
static void
finalize (GObject *object)
{
NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (object);
g_free (priv->config);
G_OBJECT_CLASS (nm_setting_team_port_parent_class)->finalize (object);
}
static void
nm_setting_team_port_class_init (NMSettingTeamPortClass *setting_class)
{
@ -165,6 +176,7 @@ nm_setting_team_port_class_init (NMSettingTeamPortClass *setting_class)
/* virtual methods */
object_class->set_property = set_property;
object_class->get_property = get_property;
object_class->finalize = finalize;
parent_class->verify = verify;
/* Properties */

View file

@ -474,27 +474,24 @@ nm_setting_wired_get_s390_option (NMSettingWired *setting,
const char **out_key,
const char **out_value)
{
NMSettingWiredPrivate *priv;
guint32 num_keys;
GList *keys;
const char *_key = NULL, *_value = NULL;
const char *_key, *_value;
GHashTableIter iter;
guint i = 0;
g_return_val_if_fail (NM_IS_SETTING_WIRED (setting), FALSE);
priv = NM_SETTING_WIRED_GET_PRIVATE (setting);
num_keys = nm_setting_wired_get_num_s390_options (setting);
g_return_val_if_fail (idx < num_keys, FALSE);
keys = g_hash_table_get_keys (priv->s390_options);
_key = g_list_nth_data (keys, idx);
_value = g_hash_table_lookup (priv->s390_options, _key);
if (out_key)
*out_key = _key;
if (out_value)
*out_value = _value;
return TRUE;
g_hash_table_iter_init (&iter, NM_SETTING_WIRED_GET_PRIVATE (setting)->s390_options);
while (g_hash_table_iter_next (&iter, (gpointer) &_key, (gpointer) &_value)) {
if (i == idx) {
if (out_key)
*out_key = _key;
if (out_value)
*out_value = _value;
return TRUE;
}
i++;
}
g_return_val_if_reached (FALSE);
}
/**

View file

@ -10,6 +10,7 @@ AM_CPPFLAGS = \
-DBUILD_DIR=\"$(abs_builddir)\" \
-DTEST_CERT_DIR=\"$(top_srcdir)/libnm-core/tests/certs/\"
@VALGRIND_RULES@
TESTS = \
test-settings-defaults \
test-crypto \

View file

@ -96,7 +96,7 @@ out:
static void
test_cert (gconstpointer test_data)
{
char *path;
gs_free char *path = NULL;
GByteArray *array;
NMCryptoFileFormat format = NM_CRYPTO_FILE_FORMAT_UNKNOWN;
GError *error = NULL;
@ -153,6 +153,7 @@ test_load_private_key (const char *path,
"unexpected failure determining private key file '%s' "
"type with invalid password (expected %d, got %d)",
path, NM_CRYPTO_KEY_TYPE_UNKNOWN, key_type);
g_clear_error (&error);
return;
}
@ -183,6 +184,7 @@ test_load_private_key (const char *path,
g_byte_array_free (decrypted, TRUE);
}
g_clear_error (&error);
g_byte_array_free (array, TRUE);
}
@ -207,6 +209,7 @@ test_load_pkcs12 (const char *path,
"%d): %d %s",
path, NM_CRYPTO_FILE_FORMAT_PKCS12, format, error->code, error->message);
}
g_clear_error (&error);
}
static void

View file

@ -30,6 +30,7 @@
#include <sys/resource.h>
#include <nm-utils.h>
#include "gsystem-local-alloc.h"
#include "nm-setting-private.h"
#include "nm-setting-connection.h"
@ -310,6 +311,13 @@ test_setting_vpn_modify_during_foreach (void)
g_object_unref (s_vpn);
}
static void
_g_value_array_free (void *ptr)
{
if (ptr)
g_value_array_free ((GValueArray *) ptr);
}
#define OLD_DBUS_TYPE_G_IP6_ADDRESS (dbus_g_type_get_struct ("GValueArray", DBUS_TYPE_G_UCHAR_ARRAY, G_TYPE_UINT, G_TYPE_INVALID))
#define OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS (dbus_g_type_get_collection ("GPtrArray", OLD_DBUS_TYPE_G_IP6_ADDRESS))
@ -338,7 +346,7 @@ test_setting_ip6_config_old_address_array (void)
g_value_init (&written_value, OLD_DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS);
addresses = g_ptr_array_new ();
addresses = g_ptr_array_new_full (0, _g_value_array_free);
array = g_value_array_new (3);
/* IP address */
@ -398,6 +406,7 @@ test_setting_ip6_config_old_address_array (void)
ASSERT (memcmp (ba->data, &gw[0], sizeof (gw)) == 0,
"ip6-old-addr", "unexpected failure comparing gateways");
g_ptr_array_unref (addresses);
g_value_unset (&written_value);
g_value_unset (&read_value);
g_object_unref (s_ip6);
@ -406,7 +415,7 @@ test_setting_ip6_config_old_address_array (void)
static void
test_setting_gsm_apn_spaces (void)
{
NMSettingGsm *s_gsm;
gs_unref_object NMSettingGsm *s_gsm = NULL;
const char *tmp;
s_gsm = (NMSettingGsm *) nm_setting_gsm_new ();
@ -434,7 +443,7 @@ test_setting_gsm_apn_spaces (void)
static void
test_setting_gsm_apn_bad_chars (void)
{
NMSettingGsm *s_gsm;
gs_unref_object NMSettingGsm *s_gsm = NULL;
s_gsm = (NMSettingGsm *) nm_setting_gsm_new ();
ASSERT (s_gsm != NULL,
@ -472,7 +481,7 @@ test_setting_gsm_apn_bad_chars (void)
static void
test_setting_gsm_apn_underscore (void)
{
NMSettingGsm *s_gsm;
gs_unref_object NMSettingGsm *s_gsm = NULL;
GError *error = NULL;
gboolean success;
@ -491,7 +500,7 @@ test_setting_gsm_apn_underscore (void)
static void
test_setting_gsm_without_number (void)
{
NMSettingGsm *s_gsm;
gs_unref_object NMSettingGsm *s_gsm = NULL;
GError *error = NULL;
gboolean success;
@ -1573,6 +1582,7 @@ test_connection_good_base_types (void)
NM_SETTING_GSM_APN, "metered.billing.sucks",
NULL);
nm_connection_add_setting (connection, setting);
g_clear_object (&connection);
/* CDMA connection */
connection = nm_connection_new ();
@ -1671,7 +1681,7 @@ test_connection_bad_base_types (void)
static void
test_setting_compare_id (void)
{
NMSetting *old, *new;
gs_unref_object NMSetting *old = NULL, *new = NULL;
gboolean success;
old = nm_setting_connection_new ();
@ -1697,7 +1707,7 @@ test_setting_compare_secrets (NMSettingSecretFlags secret_flags,
NMSettingCompareFlags comp_flags,
gboolean remove_secret)
{
NMSetting *old, *new;
gs_unref_object NMSetting *old = NULL, *new = NULL;
gboolean success;
/* Make sure that a connection with transient/unsaved secrets compares
@ -1729,7 +1739,7 @@ test_setting_compare_vpn_secrets (NMSettingSecretFlags secret_flags,
NMSettingCompareFlags comp_flags,
gboolean remove_secret)
{
NMSetting *old, *new;
gs_unref_object NMSetting *old = NULL, *new = NULL;
gboolean success;
/* Make sure that a connection with transient/unsaved secrets compares
@ -1908,7 +1918,7 @@ test_setting_connection_changed_signal (void)
NMConnection *connection;
gboolean changed = FALSE;
NMSettingConnection *s_con;
char *uuid;
gs_free char *uuid = NULL;
connection = nm_connection_new ();
g_signal_connect (connection,
@ -2318,7 +2328,7 @@ static void
test_setting_old_uuid (void)
{
GError *error = NULL;
NMSetting *setting;
gs_unref_object NMSetting *setting = NULL;
gboolean success;
/* NetworkManager-0.9.4.0 generated 40-character UUIDs with no dashes,

View file

@ -176,6 +176,7 @@ test_need_tls_secrets_path (void)
"need-tls-secrets-path-key-password",
"expected to require private key password, but it wasn't");
g_ptr_array_free (hints, TRUE);
g_object_unref (connection);
}
@ -219,6 +220,7 @@ test_need_tls_secrets_blob (void)
"need-tls-secrets-blob-key-password",
"expected to require private key password, but it wasn't");
g_ptr_array_free (hints, TRUE);
g_object_unref (connection);
}
@ -345,6 +347,7 @@ test_need_tls_phase2_secrets_path (void)
"need-tls-phase2-secrets-path-key-password",
"expected to require private key password, but it wasn't");
g_ptr_array_free (hints, TRUE);
g_object_unref (connection);
}
@ -389,6 +392,7 @@ test_need_tls_phase2_secrets_blob (void)
"need-tls-phase2-secrets-blob-key-password",
"expected to require private key password, but it wasn't");
g_ptr_array_free (hints, TRUE);
g_object_unref (connection);
}
@ -507,6 +511,7 @@ test_update_secrets_wifi_single_setting (void)
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 0);
g_assert_cmpstr (tmp, ==, wepkey);
g_hash_table_unref (secrets);
g_object_unref (connection);
}
@ -547,6 +552,7 @@ test_update_secrets_wifi_full_hash (void)
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 0);
g_assert_cmpstr (tmp, ==, wepkey);
g_hash_table_unref (all);
g_object_unref (connection);
}
@ -577,6 +583,8 @@ test_update_secrets_wifi_bad_setting_name (void)
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND);
g_assert (success == FALSE);
g_clear_error (&error);
g_hash_table_unref (secrets);
g_object_unref (connection);
}
@ -600,7 +608,7 @@ test_update_secrets_whole_connection (void)
secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
wsec_hash = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
g_assert (wsec_hash);
g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
g_hash_table_insert (wsec_hash, g_strdup (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), string_to_gvalue (wepkey));
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
g_assert_no_error (error);
@ -610,6 +618,7 @@ test_update_secrets_whole_connection (void)
g_assert (s_wsec);
g_assert_cmpstr (nm_setting_wireless_security_get_wep_key (s_wsec, 0), ==, wepkey);
g_hash_table_unref (secrets);
g_object_unref (connection);
}
@ -629,6 +638,7 @@ test_update_secrets_whole_connection_empty_hash (void)
g_assert_no_error (error);
g_assert (success == TRUE);
g_object_unref (connection);
g_hash_table_unref (secrets);
}
static void
@ -650,20 +660,23 @@ test_update_secrets_whole_connection_bad_setting (void)
secrets = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_ALL);
wsec_hash = g_hash_table_lookup (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
g_assert (wsec_hash);
g_hash_table_insert (wsec_hash, NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, string_to_gvalue (wepkey));
g_hash_table_insert (wsec_hash, g_strdup (NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), string_to_gvalue (wepkey));
/* Steal the wsec setting hash so it's not deallocated, and stuff it back
* in with a different name so we ensure libnm-util is returning the right
* error when it finds an entry in the connection hash that doesn't match
* any setting in the connection.
*/
g_hash_table_steal (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
g_hash_table_insert (secrets, "asdfasdfasdfasdf", wsec_hash);
g_hash_table_ref (wsec_hash);
g_hash_table_remove (secrets, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
g_hash_table_insert (secrets, g_strdup ("asdfasdfasdfasdf"), wsec_hash);
success = nm_connection_update_secrets (connection, NULL, secrets, &error);
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND);
g_assert (success == FALSE);
g_clear_error (&error);
g_hash_table_destroy (secrets);
g_object_unref (connection);
}
@ -716,6 +729,7 @@ test_update_secrets_null_setting_name_with_setting_hash (void)
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_SETTING_NOT_FOUND);
g_assert (!success);
g_clear_error (&error);
g_hash_table_destroy (secrets);
g_object_unref (connection);
}

View file

@ -188,6 +188,7 @@ test_phase2_private_key_import (const char *path,
g_object_get (s_8021x, NM_SETTING_802_1X_PHASE2_PRIVATE_KEY, &tmp_key, NULL);
ASSERT (tmp_key != NULL, "phase2-private-key-import", "missing private key value");
check_scheme_path (tmp_key, path);
g_byte_array_free (tmp_key, TRUE);
} else
g_assert_not_reached ();
@ -249,6 +250,7 @@ test_wrong_password_keeps_data (const char *path, const char *password)
"wrong-password-keeps-data", "unexpected missing error");
ASSERT (format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"wrong-password-keeps-data", "unexpected success reading private key format");
g_clear_error (&error);
/* Make sure the password hasn't changed */
pw = nm_setting_802_1x_get_private_key_password (s_8021x);
@ -346,6 +348,7 @@ test_wrong_phase2_password_keeps_data (const char *path, const char *password)
"wrong-phase2-password-keeps-data", "unexpected missing error");
ASSERT (format == NM_SETTING_802_1X_CK_FORMAT_UNKNOWN,
"wrong-phase2-password-keeps-data", "unexpected success reading private key format");
g_clear_error (&error);
/* Make sure the password hasn't changed */
pw = nm_setting_802_1x_get_phase2_private_key_password (s_8021x);

View file

@ -26,6 +26,7 @@
#include <nm-utils.h>
#include <nm-glib-compat.h>
#include "nm-setting-dcb.h"
#include "gsystem-local-alloc.h"
#define DCB_FLAGS_ALL (NM_SETTING_DCB_FLAG_ENABLE | \
NM_SETTING_DCB_FLAG_ADVERTISE | \
@ -34,7 +35,7 @@
static void
test_dcb_flags_valid (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;
guint i;
@ -87,7 +88,7 @@ test_dcb_flags_valid (void)
static void
test_dcb_flags_invalid (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;
@ -146,7 +147,7 @@ test_dcb_flags_invalid (void)
static void
test_dcb_app_priorities (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;
@ -208,7 +209,7 @@ test_dcb_app_priorities (void)
static void
test_dcb_priorities_valid (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;
guint i;
@ -267,7 +268,7 @@ test_dcb_priorities_valid (void)
static void
test_dcb_bandwidth_sums (void)
{
NMSettingDcb *s_dcb;
gs_unref_object NMSettingDcb *s_dcb = NULL;
GError *error = NULL;
gboolean success;

View file

@ -349,6 +349,7 @@ _nm_dbus_bind_properties (gpointer object, gpointer skeleton)
skeleton, properties[i]->name,
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
}
g_free (properties);
}
static char *

View file

@ -17,6 +17,11 @@ LDADD = \
noinst_PROGRAMS = $(TESTS)
if WITH_VALGRIND
@VALGRIND_RULES@ --launch-dbus
else
TESTS_ENVIRONMENT = $(srcdir)/libnm-test-launch.sh
endif
TESTS = test-nm-client test-remote-settings-client test-secret-agent
test_nm_client_SOURCES = \
@ -33,9 +38,6 @@ test_secret_agent_SOURCES = \
common.c \
common.h \
test-secret-agent.c
TESTS_ENVIRONMENT = $(srcdir)/libnm-test-launch.sh
endif
EXTRA_DIST = libnm-test-launch.sh

View file

@ -370,7 +370,7 @@ add_remove_cb (GObject *s,
{
NMRemoteConnection *connection;
gboolean *done = user_data;
GError *error = NULL;
gs_free_error GError *error = NULL;
connection = nm_client_add_connection_finish (client, result, &error);
g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_OBJECT_CREATION_FAILED);
@ -426,7 +426,7 @@ add_bad_cb (GObject *s,
gpointer user_data)
{
gboolean *done = user_data;
GError *error = NULL;
gs_free_error GError *error = NULL;
remote = nm_client_add_connection_finish (client, result, &error);
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY);
@ -469,7 +469,7 @@ save_hostname_cb (GObject *s,
gpointer user_data)
{
gboolean *done = user_data;
GError *error = NULL;
gs_free_error GError *error = NULL;
nm_client_save_hostname_finish (client, result, &error);
g_assert_no_error (error);

View file

@ -354,7 +354,7 @@ connection_activated_none_cb (GObject *c,
{
TestSecretAgentData *sadata = user_data;
NMActiveConnection *ac;
GError *error = NULL;
gs_free_error GError *error = NULL;
ac = nm_client_activate_connection_finish (sadata->client, result, &error);
g_assert_error (error, NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_NO_SECRETS);
@ -399,8 +399,8 @@ connection_activated_no_secrets_cb (GObject *c,
gpointer user_data)
{
TestSecretAgentData *sadata = user_data;
NMActiveConnection *ac;
GError *error = NULL;
gs_unref_object NMActiveConnection *ac = NULL;
gs_free_error GError *error = NULL;
ac = nm_client_activate_connection_finish (sadata->client, result, &error);
g_assert_error (error, NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_NO_SECRETS);
@ -434,8 +434,8 @@ connection_activated_cancel_cb (GObject *c,
gpointer user_data)
{
TestSecretAgentData *sadata = user_data;
NMActiveConnection *ac;
GError *error = NULL;
gs_unref_object NMActiveConnection *ac = NULL;
gs_free_error GError *error = NULL;
ac = nm_client_activate_connection_finish (sadata->client, result, &error);
g_assert_error (error, NM_AGENT_MANAGER_ERROR, NM_AGENT_MANAGER_ERROR_USER_CANCELED);

View file

@ -8356,7 +8356,7 @@ dispose (GObject *object)
_cleanup_generic_post (self, FALSE);
g_clear_pointer (&priv->ip6_saved_properties, g_hash_table_unref);
g_hash_table_remove_all (priv->ip6_saved_properties);
if (priv->recheck_assume_id) {
g_source_remove (priv->recheck_assume_id);
@ -8372,8 +8372,7 @@ dispose (GObject *object)
priv->con_provider = NULL;
}
g_hash_table_unref (priv->available_connections);
priv->available_connections = NULL;
g_hash_table_remove_all (priv->available_connections);
if (priv->carrier_wait_id) {
g_source_remove (priv->carrier_wait_id);
@ -8410,6 +8409,9 @@ finalize (GObject *object)
g_free (priv->type_desc);
g_free (priv->dhcp_anycast_address);
g_hash_table_unref (priv->ip6_saved_properties);
g_hash_table_unref (priv->available_connections);
G_OBJECT_CLASS (nm_device_parent_class)->finalize (object);
}

View file

@ -23,5 +23,6 @@ test_wifi_ap_utils_SOURCES = \
test_wifi_ap_utils_LDADD = $(top_builddir)/src/libNetworkManager.la
@VALGRIND_RULES@
TESTS = test-wifi-ap-utils

View file

@ -785,6 +785,7 @@ test_priv_ap_leap_connection_1 (gconstpointer add_wifi)
COMPARE (src, expected, success, error, 0, 0);
g_object_unref (src);
g_object_unref (expected);
}
/*******************************************/
@ -866,6 +867,7 @@ test_priv_ap_dynamic_wep_1 (void)
COMPARE (src, expected, success, error, 0, 0);
g_object_unref (src);
g_object_unref (expected);
}
/*******************************************/
@ -913,6 +915,7 @@ test_priv_ap_dynamic_wep_2 (void)
COMPARE (src, expected, success, error, 0, 0);
g_object_unref (src);
g_object_unref (expected);
}
/*******************************************/

View file

@ -140,6 +140,7 @@ process_dhclient_rfc3442_route (const char **octets,
g_free (str_addr);
goto error;
}
g_free (str_addr);
tmp_addr &= nm_utils_ip4_prefix_to_netmask ((guint32) tmp);
route->network = tmp_addr;
}

View file

@ -37,6 +37,7 @@ test_dhcp_utils_LDADD = \
#################################
@VALGRIND_RULES@
TESTS = test-dhcp-dhclient test-dhcp-utils
EXTRA_DIST = \

View file

@ -482,6 +482,9 @@ test_one_duid (const char *escaped, const guint8 *unescaped, guint len)
g_assert (w);
g_assert_cmpint (strlen (escaped), ==, strlen (w));
g_assert_cmpstr (escaped, ==, w);
g_byte_array_free (t, TRUE);
g_free (w);
}
static void

View file

@ -19,5 +19,6 @@ test_dnsmasq_utils_SOURCES = \
test_dnsmasq_utils_LDADD = \
$(top_builddir)/src/libNetworkManager.la
@VALGRIND_RULES@
TESTS = test-dnsmasq-utils

View file

@ -207,7 +207,6 @@ main (int argc, char *argv[])
NMManager *manager = NULL;
gs_unref_object NMVpnManager *vpn_manager = NULL;
gs_unref_object NMDnsManager *dns_mgr = NULL;
gs_unref_object NMDBusManager *dbus_mgr = NULL;
gs_unref_object NMSupplicantManager *sup_mgr = NULL;
gs_unref_object NMDhcpManager *dhcp_mgr = NULL;
gs_unref_object NMFirewallManager *fw_mgr = NULL;
@ -397,10 +396,6 @@ main (int argc, char *argv[])
nm_auth_manager_setup (nm_config_get_auth_polkit (config));
/* Initialize our DBus service & connection */
dbus_mgr = nm_dbus_manager_get ();
g_assert (dbus_mgr != NULL);
vpn_manager = nm_vpn_manager_get ();
g_assert (vpn_manager != NULL);
@ -445,7 +440,7 @@ main (int argc, char *argv[])
session_monitor = nm_session_monitor_get ();
g_assert (session_monitor != NULL);
if (!nm_dbus_manager_get_connection (dbus_mgr)) {
if (!nm_dbus_manager_get_connection (nm_dbus_manager_get ())) {
#if HAVE_DBUS_GLIB_100
nm_log_warn (LOGD_CORE, "Failed to connect to D-Bus; only private bus is available");
#else
@ -454,7 +449,7 @@ main (int argc, char *argv[])
#endif
} else {
/* Start our DBus service */
if (!nm_dbus_manager_start_service (dbus_mgr)) {
if (!nm_dbus_manager_start_service (nm_dbus_manager_get ())) {
nm_log_err (LOGD_CORE, "failed to start the dbus service.");
goto done;
}

View file

@ -37,7 +37,7 @@
if (nm_logging_enabled ((level), (domain))) { \
char __prefix[30] = "auth"; \
\
if ((self) != _instance) \
if ((self) != singleton_instance) \
g_snprintf (__prefix, sizeof (__prefix), "auth[%p]", (self)); \
nm_log ((level), (domain), \
"%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
@ -76,7 +76,7 @@ typedef struct {
#endif
} NMAuthManagerPrivate;
static NMAuthManager *_instance = NULL;
static NMAuthManager *singleton_instance = NULL;
G_DEFINE_TYPE (NMAuthManager, nm_auth_manager, G_TYPE_OBJECT)
@ -485,9 +485,9 @@ _dbus_new_proxy_cb (GObject *source_object,
NMAuthManager *
nm_auth_manager_get ()
{
g_return_val_if_fail (_instance, NULL);
g_return_val_if_fail (singleton_instance, NULL);
return _instance;
return singleton_instance;
}
NMAuthManager *
@ -495,14 +495,14 @@ nm_auth_manager_setup (gboolean polkit_enabled)
{
NMAuthManager *self;
g_return_val_if_fail (!_instance, _instance);
g_return_val_if_fail (!singleton_instance, singleton_instance);
self = g_object_new (NM_TYPE_AUTH_MANAGER,
NM_AUTH_MANAGER_POLKIT_ENABLED, polkit_enabled,
NULL);
_LOGD ("set instance");
return (_instance = self);
return (singleton_instance = self);
}
/*****************************************************************************/
@ -616,8 +616,8 @@ finalize (GObject *object)
G_OBJECT_CLASS (nm_auth_manager_parent_class)->finalize (object);
if (self == _instance) {
_instance = NULL;
if (self == singleton_instance) {
singleton_instance = NULL;
_LOGD ("unset instance");
}
}

View file

@ -275,14 +275,18 @@ merge_no_auto_default_state (NMConfig *config)
if (g_file_get_contents (priv->no_auto_default_file, &data, NULL, NULL)) {
list = g_strsplit (data, "\n", -1);
for (i = 0; list[i]; i++) {
if (!*list[i])
if (!*list[i]) {
g_free (list[i]);
continue;
}
for (j = 0; j < updated->len; j++) {
if (!strcmp (list[i], updated->pdata[j]))
break;
}
if (j == updated->len)
g_ptr_array_add (updated, list[i]);
else
g_free (list[i]);
}
g_free (list);
g_free (data);
@ -407,8 +411,8 @@ read_config (NMConfig *config, const char *path, GError **error)
if (keys[k][len - 1] == '+') {
char *base_key = g_strndup (keys[k], len - 1);
const char *old_val = g_key_file_get_value (priv->keyfile, groups[g], base_key, NULL);
const char *new_val = g_key_file_get_value (kf, groups[g], keys[k], NULL);
char *old_val = g_key_file_get_value (priv->keyfile, groups[g], base_key, NULL);
char *new_val = g_key_file_get_value (kf, groups[g], keys[k], NULL);
if (old_val && *old_val) {
char *combined = g_strconcat (old_val, ",", new_val, NULL);
@ -419,6 +423,8 @@ read_config (NMConfig *config, const char *path, GError **error)
g_key_file_set_value (priv->keyfile, groups[g], base_key, new_val);
g_free (base_key);
g_free (old_val);
g_free (new_val);
continue;
}

View file

@ -78,20 +78,33 @@ static void nm_dbus_manager_cleanup (NMDBusManager *self, gboolean dispose);
static void start_reconnection_timeout (NMDBusManager *self);
static void object_destroyed (NMDBusManager *self, gpointer object);
NM_DEFINE_SINGLETON_DESTRUCTOR (NMDBusManager);
NM_DEFINE_SINGLETON_WEAK_REF (NMDBusManager);
NMDBusManager *
nm_dbus_manager_get (void)
{
static NMDBusManager *singleton = NULL;
static gsize once = 0;
if (g_once_init_enter (&once)) {
singleton = (NMDBusManager *) g_object_new (NM_TYPE_DBUS_MANAGER, NULL);
g_assert (singleton);
if (!nm_dbus_manager_init_bus (singleton))
start_reconnection_timeout (singleton);
g_once_init_leave (&once, 1);
if (G_UNLIKELY (!singleton_instance)) {
nm_dbus_manager_setup (g_object_new (NM_TYPE_DBUS_MANAGER, NULL));
if (!nm_dbus_manager_init_bus (singleton_instance))
start_reconnection_timeout (singleton_instance);
}
return singleton;
return singleton_instance;
}
void
nm_dbus_manager_setup (NMDBusManager *instance)
{
static char already_setup = FALSE;
g_assert (NM_IS_DBUS_MANAGER (instance));
g_assert (!already_setup);
g_assert (!singleton_instance);
already_setup = TRUE;
singleton_instance = instance;
nm_singleton_instance_weak_ref_register ();
nm_log_dbg (LOGD_CORE, "create %s singleton (%p)", "NMDBusManager", singleton_instance);
}
/**************************************************************/
@ -199,6 +212,7 @@ private_server_new (const char *path,
nm_log_warn (LOGD_CORE, "(%s) failed to set up private socket %s: %s",
tag, address, error.message);
dbus_error_free (&error);
g_free (address);
return NULL;
}

View file

@ -73,6 +73,7 @@ typedef struct {
GType nm_dbus_manager_get_type (void);
NMDBusManager * nm_dbus_manager_get (void);
void nm_dbus_manager_setup (NMDBusManager *instance);
char * nm_dbus_manager_get_name_owner (NMDBusManager *self,
const char *name,

View file

@ -60,7 +60,7 @@ typedef struct {
G_DEFINE_TYPE (NMDefaultRouteManager, nm_default_route_manager, G_TYPE_OBJECT)
static NMDefaultRouteManager *_instance;
static NMDefaultRouteManager *singleton_instance;
#define _LOG(level, addr_family, ...) \
G_STMT_START { \
@ -71,7 +71,7 @@ static NMDefaultRouteManager *_instance;
char __ch = __addr_family == AF_INET ? '4' : (__addr_family == AF_INET6 ? '6' : '-'); \
char __prefix[30] = "default-route"; \
\
if ((self) != _instance) \
if ((self) != singleton_instance) \
g_snprintf (__prefix, sizeof (__prefix), "default-route%c[%p]", __ch, (self)); \
else \
__prefix[STRLEN ("default-route")] = __ch; \
@ -1205,11 +1205,11 @@ static const VTableIP vtable_ip6 = {
NMDefaultRouteManager *
nm_default_route_manager_get ()
{
if (G_UNLIKELY (!_instance)) {
_instance = NM_DEFAULT_ROUTE_MANAGER (g_object_new (NM_TYPE_DEFAULT_ROUTE_MANAGER, NULL));
g_object_add_weak_pointer (G_OBJECT (_instance), (gpointer *) &_instance);
if (G_UNLIKELY (!singleton_instance)) {
singleton_instance = NM_DEFAULT_ROUTE_MANAGER (g_object_new (NM_TYPE_DEFAULT_ROUTE_MANAGER, NULL));
g_object_add_weak_pointer (G_OBJECT (singleton_instance), (gpointer *) &singleton_instance);
}
return _instance;
return singleton_instance;
}
/***********************************************************************************/

View file

@ -109,7 +109,7 @@ test_cleanup_linux_CPPFLAGS = \
-DKERNEL_HACKS=1
test_cleanup_linux_LDADD = $(PLATFORM_LDADD)
#@VALGRIND_RULES@
@VALGRIND_RULES@
TESTS = test-link-fake test-address-fake test-route-fake test-cleanup-fake test-address-linux test-route-linux test-cleanup-linux

View file

@ -148,20 +148,20 @@ init_inotify (NMInotifyHelper *self)
NMInotifyHelper *
nm_inotify_helper_get (void)
{
static NMInotifyHelper *singleton = NULL;
static NMInotifyHelper *singleton_instance = NULL;
if (!singleton) {
singleton = (NMInotifyHelper *) g_object_new (NM_TYPE_INOTIFY_HELPER, NULL);
if (!singleton_instance) {
singleton_instance = (NMInotifyHelper *) g_object_new (NM_TYPE_INOTIFY_HELPER, NULL);
if (!init_inotify (singleton)) {
g_clear_object (&singleton);
if (!init_inotify (singleton_instance)) {
g_clear_object (&singleton_instance);
return NULL;
}
} else
g_object_ref (singleton);
g_object_ref (singleton_instance);
g_assert (singleton);
return singleton;
g_assert (singleton_instance);
return singleton_instance;
}
static void

View file

@ -186,6 +186,7 @@ done:
if (lines)
g_strfreev (lines);
g_free (out);
g_free (err);
if (success)
*out_blocks = blocks;
else

View file

@ -32,6 +32,7 @@ test_ibft_SOURCES = \
test_ibft_LDADD = \
$(top_builddir)/src/libNetworkManager.la
@VALGRIND_RULES@
TESTS = test-ibft
endif

View file

@ -63,7 +63,7 @@ read_block (const char *iscsiadm_path, const char *expected_mac)
}
g_assert (block);
g_slist_foreach (blocks, (GFunc) g_ptr_array_unref, NULL);
g_slist_free_full (blocks, (GDestroyNotify) g_ptr_array_unref);
return block;
}
@ -110,6 +110,7 @@ test_read_ibft_dhcp (void)
g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
g_object_unref (connection);
g_ptr_array_unref (block);
}
static void
@ -266,7 +267,7 @@ test_read_ibft_vlan (void)
g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, NULL);
g_object_unref (connection);
g_ptr_array_ref (block);
g_ptr_array_unref (block);
}
NMTST_DEFINE ();

View file

@ -540,8 +540,6 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
char **lines = NULL, **iter;
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
GMatchInfo *match_info;
NMIPRoute *route = NULL;
char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL;
gint64 prefix_int, metric_int;
gboolean success = FALSE;
@ -573,6 +571,9 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
/* Iterate through file lines */
lines = g_strsplit_set (contents, "\n\r", -1);
for (iter = lines; iter && *iter; iter++) {
gs_free char *next_hop = NULL, *dest = NULL;
char *prefix, *metric;
NMIPRoute *route;
/* Skip empty lines */
if (g_regex_match_simple (pattern_empty, *iter, 0, 0))
@ -592,11 +593,10 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
}
dest = g_match_info_fetch (match_info, 1);
if (!strcmp (dest, "default"))
strcpy (dest, "0.0.0.0");
strcpy (dest, "0.0.0.0");
if (!nm_utils_ipaddr_valid (AF_INET, dest)) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route destination address '%s'", dest);
g_free (dest);
g_match_info_free (match_info);
goto error;
}
@ -611,7 +611,6 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
if (errno || prefix_int <= 0 || prefix_int > 32) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route destination prefix '%s'", prefix);
g_free (dest);
g_free (prefix);
goto error;
}
@ -627,13 +626,10 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
"Invalid IP4 route gateway address '%s'",
next_hop);
g_match_info_free (match_info);
g_free (dest);
g_free (next_hop);
goto error;
}
} else {
/* we don't make distinction between missing GATEWAY IP and 0.0.0.0 */
next_hop = NULL;
}
g_match_info_free (match_info);
@ -648,8 +644,6 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
g_match_info_free (match_info);
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
"Invalid IP4 route metric '%s'", metric);
g_free (dest);
g_free (next_hop);
g_free (metric);
goto error;
}
@ -658,13 +652,11 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
g_match_info_free (match_info);
route = nm_ip_route_new (AF_INET, dest, prefix_int, next_hop, metric_int, error);
if (!route) {
g_free (dest);
g_free (next_hop);
if (!route)
goto error;
}
if (!nm_setting_ip_config_add_route (s_ip4, route))
PARSE_WARNING ("duplicate IP4 route");
nm_ip_route_unref (route);
}
success = TRUE;
@ -672,8 +664,6 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
error:
g_free (contents);
g_strfreev (lines);
if (route)
nm_ip_route_unref (route);
g_regex_unref (regex_to1);
g_regex_unref (regex_to2);
g_regex_unref (regex_via);
@ -749,7 +739,6 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
char **lines = NULL, **iter;
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
GMatchInfo *match_info;
NMIPRoute *route = NULL;
char *dest = NULL, *prefix = NULL, *next_hop = NULL, *metric = NULL;
gint64 prefix_int, metric_int;
gboolean success = FALSE;
@ -782,6 +771,7 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
/* Iterate through file lines */
lines = g_strsplit_set (contents, "\n\r", -1);
for (iter = lines; iter && *iter; iter++) {
NMIPRoute *route;
/* Skip empty lines */
if (g_regex_match_simple (pattern_empty, *iter, 0, 0))
@ -871,6 +861,7 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
goto error;
if (!nm_setting_ip_config_add_route (s_ip6, route))
PARSE_WARNING ("duplicate IP6 route");
nm_ip_route_unref (route);
}
success = TRUE;
@ -878,8 +869,6 @@ read_route6_file (const char *filename, NMSettingIPConfig *s_ip6, GError **error
error:
g_free (contents);
g_strfreev (lines);
if (route)
nm_ip_route_unref (route);
g_regex_unref (regex_to1);
g_regex_unref (regex_to2);
g_regex_unref (regex_via);
@ -3080,7 +3069,8 @@ make_wpa_setting (shvarFile *ifcfg,
if (psk) {
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_PSK, psk, NULL);
g_free (psk);
}
} else if (error)
goto error;
}
if (adhoc)
@ -4466,6 +4456,7 @@ make_vlan_setting (shvarFile *ifcfg,
goto error;
}
g_object_set (s_vlan, NM_SETTING_VLAN_PARENT, parent, NULL);
g_clear_pointer (&parent, g_free);
if (svTrueValue (ifcfg, "REORDER_HDR", FALSE))
vlan_flags |= NM_VLAN_FLAG_REORDER_HEADERS;
@ -4484,6 +4475,8 @@ make_vlan_setting (shvarFile *ifcfg,
parse_prio_map_list (s_vlan, ifcfg, "VLAN_INGRESS_PRIORITY_MAP", NM_VLAN_INGRESS_MAP);
parse_prio_map_list (s_vlan, ifcfg, "VLAN_EGRESS_PRIORITY_MAP", NM_VLAN_EGRESS_MAP);
g_free (iface_name);
return (NMSetting *) s_vlan;
error:
@ -4657,7 +4650,8 @@ connection_from_file_full (const char *filename,
{
NMConnection *connection = NULL;
shvarFile *parsed;
char *type, *devtype, *bootproto;
gs_free char *type = NULL;
char *devtype, *bootproto;
NMSetting *s_ip4, *s_ip6, *s_port, *s_dcb = NULL;
const char *ifcfg_name = NULL;
@ -4701,8 +4695,6 @@ connection_from_file_full (const char *filename,
}
g_free (bootproto);
type = NULL;
devtype = svGetValue (parsed, "DEVICETYPE", FALSE);
if (devtype) {
if (!strcasecmp (devtype, TYPE_TEAM))
@ -4790,7 +4782,6 @@ connection_from_file_full (const char *filename,
PARSE_WARNING ("connection type was unrecognized but device was not uniquely identified; device may be managed");
goto done;
}
g_free (type);
if (!connection)
goto done;

View file

@ -372,10 +372,12 @@ svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim)
if (oldval) {
/* delete line */
s->lineList = g_list_remove_link (s->lineList, s->current);
g_free (s->current->data);
g_list_free_1 (s->current);
s->modified = TRUE;
}
goto bail; /* do not need keyValue */
g_free (keyValue);
goto end;
}
if (!oldval) {
@ -387,21 +389,19 @@ svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim)
if (strcmp (oldval, newval) != 0) {
/* change line */
if (s->current)
if (s->current) {
g_free (s->current->data);
s->current->data = keyValue;
else
} else
s->lineList = g_list_append (s->lineList, keyValue);
s->modified = TRUE;
}
} else
g_free (keyValue);
end:
g_free (newval);
g_free (oldval);
return;
bail:
g_free (keyValue);
goto end;
}
/* Write the current contents iff modified. Returns FALSE on error

View file

@ -47,6 +47,7 @@ test_ifcfg_rh_utils_SOURCES = \
test_ifcfg_rh_utils_LDADD = \
$(top_builddir)/src/libNetworkManager.la
@VALGRIND_RULES@
TESTS = test-ifcfg-rh-utils test-ifcfg-rh
endif

View file

@ -377,7 +377,7 @@ test_read_unmanaged_unrecognized (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
char *unhandled_spec = NULL;
gs_free char *unhandled_spec = NULL;
GError *error = NULL;
const char *expected_id = "PigeonNet";
guint64 expected_timestamp = 0;
@ -408,7 +408,7 @@ test_read_unrecognized (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
char *unhandled_spec = NULL;
gs_free char *unhandled_spec = NULL;
GError *error = NULL;
const char *expected_id = "U Can't Touch This";
guint64 expected_timestamp = 0;
@ -5341,6 +5341,7 @@ test_read_wifi_band_a_channel_mismatch (void)
NULL, TYPE_WIRELESS, NULL, &error);
g_assert (connection == NULL);
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_clear_error (&error);
}
static void
@ -5353,6 +5354,7 @@ test_read_wifi_band_bg_channel_mismatch (void)
NULL, TYPE_WIRELESS, NULL, &error);
g_assert (connection == NULL);
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_clear_error (&error);
}
#define TEST_IFCFG_WIRED_QETH_STATIC TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-qeth-static"
@ -9528,6 +9530,7 @@ test_write_wifi_wpa_then_wep_with_perms (void)
keyfile = utils_get_keys_path (testfile);
unlink (keyfile);
unlink (testfile);
g_free (keyfile);
g_free (testfile);
g_object_unref (reread);
@ -10198,6 +10201,7 @@ test_write_wired_pppoe (void)
"wired-pppoe-write", "unexpected success writing connection to disk");
g_object_unref (connection);
g_clear_error (&error);
}
static void
@ -10260,6 +10264,7 @@ test_write_vpn (void)
"vpn-write", "unexpected success writing connection to disk");
g_object_unref (connection);
g_clear_error (&error);
}
static void
@ -10342,6 +10347,7 @@ test_write_mobile_broadband (gboolean gsm)
"mobile-broadband-write", "unexpected success writing connection to disk");
g_object_unref (connection);
g_clear_error (&error);
}
#define TEST_IFCFG_BRIDGE_MAIN TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bridge-main"
@ -10802,6 +10808,7 @@ test_write_vlan (void)
unlink (written);
g_free (written);
g_object_unref (connection);
}
static void
@ -10970,6 +10977,7 @@ test_read_ibft_ignored (void)
NULL, &error);
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_assert (connection == NULL);
g_clear_error (&error);
}
#define TEST_IFCFG_BOND_MAIN TEST_IFCFG_DIR"/network-scripts/ifcfg-test-bond-main"
@ -11769,6 +11777,7 @@ test_read_dcb_bad_booleans (void)
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_assert (strstr (error->message, "invalid boolean digit"));
g_assert (connection == NULL);
g_clear_error (&error);
}
static void
@ -11786,6 +11795,7 @@ test_read_dcb_short_booleans (void)
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_assert (strstr (error->message, "boolean array must be 8 characters"));
g_assert (connection == NULL);
g_clear_error (&error);
}
static void
@ -11803,6 +11813,7 @@ test_read_dcb_bad_uints (void)
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_assert (strstr (error->message, "invalid uint digit"));
g_assert (connection == NULL);
g_clear_error (&error);
}
static void
@ -11820,6 +11831,7 @@ test_read_dcb_short_uints (void)
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_assert (strstr (error->message, "uint array must be 8 characters"));
g_assert (connection == NULL);
g_clear_error (&error);
}
static void
@ -11837,6 +11849,7 @@ test_read_dcb_bad_percent (void)
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_assert (strstr (error->message, "invalid percent element"));
g_assert (connection == NULL);
g_clear_error (&error);
}
static void
@ -11854,6 +11867,7 @@ test_read_dcb_short_percent (void)
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_assert (strstr (error->message, "percent array must be 8 elements"));
g_assert (connection == NULL);
g_clear_error (&error);
}
static void
@ -11871,6 +11885,7 @@ test_read_dcb_pgpct_not_100 (void)
g_assert_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION);
g_assert (strstr (error->message, "invalid percentage sum"));
g_assert (connection == NULL);
g_clear_error (&error);
}
static void
@ -12226,6 +12241,7 @@ test_write_team_port (void)
val = svGetValue (f, "TEAM_PORT_CONFIG", TRUE);
g_assert (val);
g_assert_cmpstr (val, ==, escaped_expected_config);
g_free (val);
val = svGetValue (f, "TEAM_MASTER", TRUE);
g_assert (val);
g_assert_cmpstr (val, ==, "team0");

View file

@ -44,6 +44,7 @@
#include <nm-utils.h>
#include "nm-logging.h"
#include "gsystem-local-alloc.h"
#include "common.h"
#include "shvar.h"
#include "reader.h"
@ -2111,13 +2112,16 @@ static void
write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path)
{
NMSettingIPConfig *s_ip4;
char *base_ifcfg_dir, *base_ifcfg_name, *base_name;
gs_free char *base_ifcfg_dir = NULL, *base_ifcfg_name = NULL;
const char*base_name;
int i, num, base_ifcfg_name_len, base_name_len;
GDir *dir;
base_ifcfg_dir = g_path_get_dirname (base_ifcfg_path);
base_ifcfg_name = g_path_get_basename (base_ifcfg_path);
base_ifcfg_name_len = strlen (base_ifcfg_name);
if (!g_str_has_prefix (base_ifcfg_name, IFCFG_TAG))
g_return_if_reached ();
base_name = base_ifcfg_name + strlen (IFCFG_TAG);
base_name_len = strlen (base_name);
@ -2189,9 +2193,6 @@ write_ip4_aliases (NMConnection *connection, char *base_ifcfg_path)
svWriteFile (ifcfg, 0644, NULL);
svCloseFile (ifcfg);
}
g_free (base_ifcfg_name);
g_free (base_ifcfg_dir);
}
static gboolean

View file

@ -23,6 +23,8 @@ test_ifupdown_SOURCES = \
test_ifupdown_LDADD = \
$(top_builddir)/src/libNetworkManager.la
# TODO: enable valgrind for ifupdown. Currently it fails.
#@VALGRIND_RULES@
TESTS = test-ifupdown
endif

View file

@ -870,6 +870,7 @@ parity_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const cha
int_val = 'X';
}
}
g_free (str_val);
}
if (!int_val)

View file

@ -34,6 +34,7 @@ test_keyfile_LDADD = \
$(DBUS_LIBS) \
$(CODE_COVERAGE_LDFLAGS)
@VALGRIND_RULES@
TESTS = test-keyfile
endif

View file

@ -1515,6 +1515,7 @@ test_write_intlike_ssid (void)
g_assert_no_error (error);
g_assert (tmp);
g_assert_cmpstr (tmp, ==, "101");
g_free (tmp);
g_key_file_free (keyfile);
@ -1601,6 +1602,7 @@ test_write_intlike_ssid_2 (void)
g_assert_no_error (error);
g_assert (tmp);
g_assert_cmpstr (tmp, ==, "11\\;12\\;13\\;");
g_free (tmp);
g_key_file_free (keyfile);
@ -2511,6 +2513,7 @@ test_write_wired_8021x_tls_connection_path (void)
tmp2 = g_path_get_dirname (testfile);
if (g_strcmp0 (tmp2, TEST_KEYFILES_DIR) == 0)
relative = TRUE;
g_free (tmp2);
/* CA cert */
tmp = g_key_file_get_string (keyfile,
@ -3115,6 +3118,7 @@ test_write_new_wired_group_name (void)
unlink (testfile);
g_free (testfile);
g_key_file_unref (kf);
g_object_unref (reread);
g_object_unref (connection);
}
@ -3253,6 +3257,7 @@ test_write_new_wireless_group_names (void)
unlink (testfile);
g_free (testfile);
g_key_file_unref (kf);
g_object_unref (reread);
g_object_unref (connection);
}

View file

@ -18,4 +18,5 @@ test_supplicant_config_SOURCES = \
test_supplicant_config_LDADD = \
$(top_builddir)/src/libNetworkManager.la
@VALGRIND_RULES@
TESTS = test-supplicant-config

View file

@ -111,7 +111,7 @@ test_wifi_open (void)
NMSettingConnection *s_con;
NMSettingWireless *s_wifi;
NMSettingIPConfig *s_ip4;
NMSupplicantConfig *config;
gs_unref_object NMSupplicantConfig *config = NULL;
GHashTable *hash;
char *uuid;
gboolean success;
@ -191,6 +191,7 @@ test_wifi_open (void)
validate_opt ("wifi-open", hash, "bssid", TYPE_KEYWORD, bssid_str, -1);
validate_opt ("wifi-open", hash, "key_mgmt", TYPE_KEYWORD, "NONE", -1);
g_hash_table_unref (hash);
g_object_unref (connection);
}
@ -206,7 +207,7 @@ test_wifi_wep_key (const char *detail,
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
NMSettingIPConfig *s_ip4;
NMSupplicantConfig *config;
gs_unref_object NMSupplicantConfig *config = NULL;
GHashTable *hash;
char *uuid;
gboolean success;
@ -305,6 +306,7 @@ test_wifi_wep_key (const char *detail,
validate_opt (detail, hash, "wep_tx_keyidx", TYPE_INT, GINT_TO_POINTER (0), -1);
validate_opt (detail, hash, "wep_key0", TYPE_BYTES, expected, expected_size);
g_hash_table_unref (hash);
g_object_unref (connection);
}
@ -343,7 +345,7 @@ test_wifi_wpa_psk (const char *detail,
NMSettingWireless *s_wifi;
NMSettingWirelessSecurity *s_wsec;
NMSettingIPConfig *s_ip4;
NMSupplicantConfig *config;
gs_unref_object NMSupplicantConfig *config = NULL;
GHashTable *hash;
char *uuid;
gboolean success;
@ -454,6 +456,7 @@ test_wifi_wpa_psk (const char *detail,
validate_opt (detail, hash, "group", TYPE_KEYWORD, "TKIP CCMP", -1);
validate_opt (detail, hash, "psk", key_type, expected, expected_size);
g_hash_table_unref (hash);
g_object_unref (connection);
}

View file

@ -86,6 +86,7 @@ EXTRA_DIST = test-secret-agent.py
###########################################
@VALGRIND_RULES@
TESTS = \
test-ip4-config \
test-ip6-config \

View file

@ -23,6 +23,7 @@ test_config_SOURCES = \
test_config_LDADD = \
$(top_builddir)/src/libNetworkManager.la
@VALGRIND_RULES@
TESTS = test-config
EXTRA_DIST = \

View file

@ -61,12 +61,6 @@ dispose (GObject *object)
g_object_class->dispose (object);
}
static void
finalize (GObject *object)
{
g_object_class->finalize (object);
}
static guint32
get_generic_capabilities (NMDevice *device)
{
@ -84,7 +78,6 @@ nm_test_device_class_init (NMTestDeviceClass *klass)
object_class->constructor = constructor;
object_class->constructed = constructed;
object_class->dispose = dispose;
object_class->finalize = finalize;
device_class->get_generic_capabilities = get_generic_capabilities;
}

View file

@ -27,6 +27,10 @@
#include <nm-config.h>
#include "nm-test-device.h"
#include "nm-fake-platform.h"
#include "nm-logging.h"
#include "nm-dbus-manager.h"
#include "nm-test-utils.h"
static void
setup_config (const char *config_file, const char *config_dir, ...)
@ -108,7 +112,7 @@ static void
test_config_non_existent (void)
{
NMConfig *config;
GError *error = NULL;
gs_free_error GError *error = NULL;
setup_config (SRCDIR "/no-such-file", "/no/such/dir", NULL);
config = nm_config_new (&error);
@ -120,7 +124,7 @@ static void
test_config_parse_error (void)
{
NMConfig *config;
GError *error = NULL;
gs_free_error GError *error = NULL;
setup_config (SRCDIR "/bad.conf", "/no/such/dir", NULL);
config = nm_config_new (&error);
@ -270,7 +274,7 @@ static void
test_config_confdir_parse_error (void)
{
NMConfig *config;
GError *error = NULL;
gs_free_error GError *error = NULL;
/* Using SRCDIR as the conf dir will pick up bad.conf */
setup_config (SRCDIR "/NetworkManager.conf", SRCDIR, NULL);
@ -279,14 +283,19 @@ test_config_confdir_parse_error (void)
g_assert_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE);
}
NMTST_DEFINE ();
int
main (int argc, char **argv)
{
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
nmtst_init_assert_logging (&argc, &argv);
g_test_init (&argc, &argv, NULL);
/* Initialize the DBus manager singleton explicitly, because it is accessed by
* the class initializer of NMDevice (used by the NMTestDevice stub).
* This way, we skip calling nm_dbus_manager_init_bus() which would
* either fail and/or cause unexpected actions in the test.
* */
nm_dbus_manager_setup (g_object_new (NM_TYPE_DBUS_MANAGER, NULL));
nm_fake_platform_setup ();

View file

@ -26,6 +26,7 @@
#include <nm-simple-connection.h>
#include <nm-setting-connection.h>
#include "nm-device-ethernet-utils.h"
#include "gsystem-local-alloc.h"
static NMConnection *
_new_connection (const char *id)
@ -45,7 +46,7 @@ _new_connection (const char *id)
static void
test_defname_no_connections (void)
{
char *name;
gs_free char *name = NULL;
name = nm_device_ethernet_utils_get_default_wired_name (NULL);
g_assert_cmpstr (name, ==, "Wired connection 1");
@ -57,7 +58,7 @@ static void
test_defname_no_conflict (void)
{
GSList *list = NULL;
char *name;
gs_free char *name = NULL;
list = g_slist_append (list, _new_connection ("asdfasdfasdfadf"));
list = g_slist_append (list, _new_connection ("work wifi"));
@ -75,7 +76,7 @@ static void
test_defname_conflict (void)
{
GSList *list = NULL;
char *name;
gs_free char *name = NULL;
list = g_slist_append (list, _new_connection ("asdfasdfasdfadf"));
list = g_slist_append (list, _new_connection ("Wired connection 1"));
@ -93,7 +94,7 @@ static void
test_defname_multiple_conflicts (void)
{
GSList *list = NULL;
char *name;
gs_free char *name = NULL;
list = g_slist_append (list, _new_connection ("random gsm connection"));
list = g_slist_append (list, _new_connection ("home wifi"));

View file

@ -3,8 +3,21 @@
LIBTOOL="$1"; shift
VALGRIND="$1"; shift
SUPPRESSIONS="$1"; shift
if [ "$1" = "--launch-dbus" ]; then
# Spawn DBus if there's none
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
eval `dbus-launch --sh-syntax`
trap "kill $DBUS_SESSION_BUS_PID" EXIT
fi
shift
fi
TEST="$1"; shift
if [ "$NMTST_NO_VALGRIND" != "" ]; then
"$TEST"
exit $?
fi
LOGFILE="valgrind-`echo "$TEST" | tr -cd '[:alpha:]-'`.log"
export G_SLICE=always-malloc
@ -19,6 +32,11 @@ $LIBTOOL --mode=execute "$VALGRIND" \
"$TEST"
RESULT=$?
if [ $RESULT -eq 0 -a "$(wc -c "$LOGFILE" | awk '{print$1}')" -ne 0 ]; then
echo "valgrind succeeded, but log is not empty: $LOGFILE"
exit 1
fi
if [ $RESULT -ne 0 -a $RESULT -ne 77 ]; then
echo "Don't forget to check the valgrind log at '`realpath $LOGFILE`'." >&2
fi

View file

@ -129,3 +129,217 @@
match-leak-kinds: possible
fun:calloc
}
{
_glib_sigaction
Memcheck:Param
rt_sigaction(act->sa_flags)
fun:__libc_sigaction
fun:unref_unix_signal_handler_unlocked
fun:g_child_watch_finalize
fun:g_source_unref_internal
fun:g_main_context_dispatch
fun:g_main_context_iterate.isra.24
fun:g_main_loop_run
...
}
{
# FIXME: dunny why this is needed. Clean up later.
_dispatcher_test
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:g_malloc
fun:g_slice_alloc
fun:g_variant_new_from_bytes
fun:g_variant_new_from_trusted
fun:parse_dhcp
fun:get_dispatcher_file
...
fun:g_test_run_suite_internal
fun:g_test_run_suite_internal
fun:g_test_run_suite
}
{
_gdbus_1
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:g_malloc
fun:g_slice_alloc
fun:g_slice_alloc0
fun:get_dispatch
fun:g_main_context_dispatch
fun:g_main_context_iterate.isra.24
fun:g_main_loop_run
fun:gdbus_shared_thread_func
fun:g_thread_proxy
fun:start_thread
fun:clone
}
{
_gdbus_2
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:g_malloc
fun:g_slice_alloc
fun:g_slice_alloc0
fun:g_main_context_push_thread_default
fun:gdbus_shared_thread_func
fun:g_thread_proxy
fun:start_thread
fun:clone
}
{
_gdbus_3
Memcheck:Leak
match-leak-kinds: definite
fun:calloc
fun:g_malloc0
fun:_g_socket_read_with_control_messages
fun:_g_dbus_worker_do_read_unlocked
fun:_g_dbus_worker_do_read_cb
fun:g_simple_async_result_complete
fun:complete_in_idle_cb
fun:g_main_context_dispatch
fun:g_main_context_iterate.isra.24
fun:g_main_loop_run
fun:gdbus_shared_thread_func
fun:g_thread_proxy
}
{
_gdbus_4
Memcheck:Leak
match-leak-kinds: definite
fun:calloc
fun:g_malloc0
fun:thread_memory_from_self.part.12
fun:g_slice_alloc
fun:g_slice_alloc0
fun:g_main_context_push_thread_default
fun:gdbus_shared_thread_func
fun:g_thread_proxy
fun:start_thread
fun:clone
}
{
_gdbus_5
Memcheck:Leak
match-leak-kinds: definite
...
fun:g_dbus_message_new_from_blob
...
}
{
_gdbus_9
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:g_malloc
fun:g_slice_alloc
fun:g_slice_alloc0
fun:get_dispatch
fun:g_main_current_source
fun:g_task_return
fun:g_task_thread_pool_thread
fun:g_thread_pool_thread_proxy
fun:g_thread_proxy
fun:start_thread
fun:clone
}
{
_gdbus_10
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:g_malloc
fun:g_slice_alloc
fun:g_slice_alloc0
fun:g_system_thread_new
fun:g_thread_new_internal
fun:g_thread_pool_start_thread.part.0
fun:g_thread_pool_push
fun:g_task_start_task_thread
fun:g_task_run_in_thread
fun:g_async_initable_real_init_async
fun:g_bus_get
}
{
_gdbus_11
Memcheck:Leak
match-leak-kinds: definite
fun:calloc
fun:g_malloc0
fun:thread_memory_from_self.part.12
fun:g_slice_alloc
fun:g_slice_alloc0
fun:get_dispatch
fun:g_main_current_source
fun:g_task_return
fun:g_task_thread_pool_thread
fun:g_thread_pool_thread_proxy
fun:g_thread_proxy
fun:start_thread
}
{
_gdbus_12
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:g_malloc
fun:g_slice_alloc
fun:g_error_new_valist
fun:g_error_new
fun:g_dbus_error_new_for_dbus_error
fun:g_dbus_error_set_dbus_error
fun:g_dbus_message_to_gerror
fun:decode_method_reply
fun:g_dbus_connection_call_sync_internal
fun:g_dbus_proxy_call_sync_internal
fun:g_dbus_proxy_call_sync
}
{
_gdbus_15
Memcheck:Leak
match-leak-kinds: definite
fun:malloc
fun:g_malloc
fun:g_slice_alloc
fun:g_hash_table_new_full
fun:demarshal_map
fun:_dbus_gvalue_demarshal
fun:dbus_g_proxy_end_call_internal
fun:dbus_g_proxy_end_call
fun:get_permissions_reply
fun:complete_pending_call_and_unlock
fun:dbus_connection_dispatch
fun:message_queue_dispatch
}
{
_gdbus_16
Memcheck:Leak
match-leak-kinds: definite
fun:calloc
fun:g_malloc0
fun:_g_dbus_worker_send_message
fun:g_dbus_connection_send_message_unlocked
fun:unsubscribe_id_internal
fun:g_dbus_connection_signal_unsubscribe
fun:g_dbus_proxy_finalize
...
}