Commit 18c0043d authored by Slava Monich's avatar Slava Monich

[test] Fixed memory leaks

parent 6530a67b
/*
* Copyright (C) 2013-2015 Jolla Ltd.
* Copyright (C) 2013-2016 Jolla Ltd.
* Contact: Slava Monich <slava.monich@jolla.com>
*
* This program is free software; you can redistribute it and/or modify
......@@ -21,7 +21,13 @@
MMS_LOG_MODULE_DEFINE("mms-connection-test");
typedef MMSConnectionClass MMSConnectionTestClass;
typedef MMSConnection MMSConnectionTest;
typedef struct mms_connection_test {
MMSConnection connection;
char* imsi;
char* mmsc;
char* mmsproxy;
char* netif;
} MMSConnectionTest;
G_DEFINE_TYPE(MMSConnectionTest, mms_connection_test, MMS_TYPE_CONNECTION);
#define MMS_TYPE_CONNECTION_TEST (mms_connection_test_get_type())
......@@ -29,7 +35,7 @@ G_DEFINE_TYPE(MMSConnectionTest, mms_connection_test, MMS_TYPE_CONNECTION);
MMS_TYPE_CONNECTION_TEST, MMSConnectionTest))
typedef struct test_connection_state_change {
MMSConnectionTest* test;
MMSConnection* conn;
MMS_CONNECTION_STATE state;
} MMSConnectionStateChange;
......@@ -39,14 +45,14 @@ test_connection_test_state_change_cb(
void* param)
{
MMSConnectionStateChange* change = param;
MMSConnectionTest* test = change->test;
if (test->state != MMS_CONNECTION_STATE_CLOSED &&
test->state != MMS_CONNECTION_STATE_FAILED &&
test->state != change->state) {
test->state = change->state;
mms_connection_signal_state_change(test);
MMSConnection* conn = change->conn;
if (conn->state != MMS_CONNECTION_STATE_CLOSED &&
conn->state != MMS_CONNECTION_STATE_FAILED &&
conn->state != change->state) {
conn->state = change->state;
mms_connection_signal_state_change(conn);
}
mms_connection_unref(change->test);
mms_connection_unref(conn);
g_free(change);
return FALSE;
}
......@@ -54,13 +60,13 @@ test_connection_test_state_change_cb(
static
gboolean
mms_connection_test_set_state(
MMSConnection* test,
MMSConnection* conn,
MMS_CONNECTION_STATE state)
{
if (test->state != MMS_CONNECTION_STATE_CLOSED) {
if (conn->state != MMS_CONNECTION_STATE_CLOSED) {
MMSConnectionStateChange* change = g_new0(MMSConnectionStateChange,1);
change->state = state;
change->test = mms_connection_ref(test);
change->conn = mms_connection_ref(conn);
g_idle_add(test_connection_test_state_change_cb, change);
}
return TRUE;
......@@ -73,21 +79,24 @@ mms_connection_test_new(
gboolean proxy)
{
MMSConnectionTest* test = g_object_new(MMS_TYPE_CONNECTION_TEST, NULL);
test->imsi = g_strdup(imsi);
MMSConnection* conn = &test->connection;
conn->imsi = test->imsi = g_strdup(imsi);
if (port) {
test->netif = g_strdup("lo");
conn->netif = test->netif = g_strdup("lo");
if (proxy) {
test->mmsc = g_strdup("http://mmsc");
test->mmsproxy = g_strdup_printf("127.0.0.1:%hu", port);
} else {
test->mmsc = g_strdup_printf("http://127.0.0.1:%hu", port);
}
conn->mmsc = test->mmsc;
conn->mmsproxy = test->mmsproxy;
}
test->type = MMS_CONNECTION_TYPE_AUTO;
test->state = MMS_CONNECTION_STATE_OPENING;
mms_connection_test_set_state(test, test->netif ?
conn->type = MMS_CONNECTION_TYPE_AUTO;
conn->state = MMS_CONNECTION_STATE_OPENING;
mms_connection_test_set_state(conn, conn->netif ?
MMS_CONNECTION_STATE_OPEN : MMS_CONNECTION_STATE_FAILED);
return test;
return conn;
}
static
......@@ -97,6 +106,18 @@ mms_connection_test_close(
{
mms_connection_test_set_state(test, MMS_CONNECTION_STATE_CLOSED);
}
static
void
mms_connection_test_finalize(
GObject* object)
{
MMSConnectionTest* test = MMS_CONNECTION_TEST(object);
g_free(test->imsi);
g_free(test->mmsc);
g_free(test->mmsproxy);
g_free(test->netif);
G_OBJECT_CLASS(mms_connection_test_parent_class)->finalize(object);
}
/**
* Per class initializer
......@@ -107,6 +128,7 @@ mms_connection_test_class_init(
MMSConnectionTestClass* klass)
{
klass->fn_close = mms_connection_test_close;
G_OBJECT_CLASS(klass)->finalize = mms_connection_test_finalize;
}
/**
......
......@@ -468,6 +468,7 @@ test_run_once(
} else {
MMS_INFO("FAILED: %s", desc->name);
}
if (error) g_error_free(error);
g_free(imsi);
g_free(imsi2);
test_finalize(&test);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment