glib: fix memory leaks in gutils, protocol, and strfuncs tests

https://bugzilla.gnome.org/show_bug.cgi?id=672329

Signed-off-by: Ravi Sankar Guntur <ravi.g@samsung.com>
This commit is contained in:
Ravi Sankar Guntur 2012-03-19 21:17:32 +05:30 committed by Matthias Clasen
parent 447a25ea50
commit aded15c9d1
3 changed files with 58 additions and 16 deletions

View File

@ -660,19 +660,32 @@ g_get_any_init_do (void)
gchar hostname[100];
g_tmp_dir = g_strdup (g_getenv ("TMPDIR"));
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
g_tmp_dir = g_strdup (g_getenv ("TMP"));
{
g_free (g_tmp_dir);
g_tmp_dir = g_strdup (g_getenv ("TMP"));
}
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
g_tmp_dir = g_strdup (g_getenv ("TEMP"));
{
g_free (g_tmp_dir);
g_tmp_dir = g_strdup (g_getenv ("TEMP"));
}
#ifdef G_OS_WIN32
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
g_tmp_dir = get_windows_directory_root ();
#else
{
g_free (g_tmp_dir);
g_tmp_dir = get_windows_directory_root ();
}
#else
#ifdef P_tmpdir
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
{
gsize k;
gsize k;
g_free (g_tmp_dir);
g_tmp_dir = g_strdup (P_tmpdir);
k = strlen (g_tmp_dir);
if (k > 1 && G_IS_DIR_SEPARATOR (g_tmp_dir[k - 1]))
@ -682,7 +695,8 @@ g_get_any_init_do (void)
if (g_tmp_dir == NULL || *g_tmp_dir == '\0')
{
g_tmp_dir = g_strdup ("/tmp");
g_free (g_tmp_dir);
g_tmp_dir = g_strdup (g_getenv ("/tmp"));
}
#endif /* !G_OS_WIN32 */

View File

@ -90,7 +90,7 @@ test_message_cb1 (GIOChannel * channel,
GIOStatus status;
guchar buf[512];
gsize read_bytes = 0;
g_assert_cmpuint (condition, ==, G_IO_IN);
for (status = g_io_channel_read_chars (channel, (gchar*)buf, sizeof (buf), &read_bytes, NULL);
@ -214,6 +214,7 @@ test_message (void)
default:
g_error ("unexpected log message type: %s", g_test_log_type_name (msg->log_type));
}
g_test_log_msg_free (msg);
}
g_assert_cmpint (passed, ==, 3);
@ -221,6 +222,7 @@ test_message (void)
g_free (argv[1]);
g_main_loop_unref (loop);
g_test_log_buffer_free (tlb);
}
static void
@ -319,10 +321,12 @@ test_error (void)
default:
g_error ("unexpected log message type: %s", g_test_log_type_name (msg->log_type));
}
g_test_log_msg_free (msg);
}
g_free (argv[1]);
g_main_loop_unref (loop);
g_test_log_buffer_free (tlb);
}
g_assert_cmpint (messages, ==, 3);

View File

@ -1122,12 +1122,21 @@ test_bounds (void)
g_strrstr_len (string, 4096, ".");
g_strrstr_len (string, 4096, "");
g_ascii_strdown (string, 4096);
g_ascii_strdown (string, 4096);
g_ascii_strup (string, 4096);
g_ascii_strup (string, 4096);
tmp = g_ascii_strup (string, 4096);
tmp2 = g_ascii_strup (tmp, 4096);
g_assert_cmpint (g_ascii_strncasecmp (string, tmp, 4096), ==, 0);
g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, 4096), ==, 0);
g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, 4096), ==, 0);
g_free (tmp);
g_free (tmp2);
g_ascii_strncasecmp (string, string, 4096);
tmp = g_ascii_strdown (string, 4096);
tmp2 = g_ascii_strdown (tmp, 4096);
g_assert_cmpint (g_ascii_strncasecmp (string, tmp, 4096), ==, 0);
g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, 4096), ==, 0);
g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, 4096), ==, 0);
g_free (tmp);
g_free (tmp2);
tmp = g_markup_escape_text (string, 4096);
g_free (tmp);
@ -1180,10 +1189,25 @@ test_bounds (void)
g_assert_cmpint (strlen (tmp), ==, 4095 + 2);
g_free (tmp);
g_ascii_strdown (string, -1);
g_ascii_strdown (string, -1);
g_ascii_strup (string, -1);
g_ascii_strup (string, -1);
tmp = g_ascii_strdown (string, -1);
tmp2 = g_ascii_strdown (tmp, -1);
g_assert_cmpint (strlen(tmp), ==, strlen(tmp2));
g_assert_cmpint (strlen(string), ==, strlen(tmp));
g_assert_cmpint (g_ascii_strncasecmp (string, tmp, -1), ==, 0);
g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, -1), ==, 0);
g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, -1), ==, 0);
g_free (tmp);
g_free (tmp2);
tmp = g_ascii_strup (string, -1);
tmp2 = g_ascii_strup (string, -1);
g_assert_cmpint (strlen(tmp), ==, strlen(tmp2));
g_assert_cmpint (strlen(string), ==, strlen(tmp));
g_assert_cmpint (g_ascii_strncasecmp (string, tmp, -1), ==, 0);
g_assert_cmpint (g_ascii_strncasecmp (string, tmp2, -1), ==, 0);
g_assert_cmpint (g_ascii_strncasecmp (tmp, tmp2, -1), ==, 0);
g_free (tmp);
g_free (tmp2);
g_ascii_strcasecmp (string, string);
g_ascii_strncasecmp (string, string, 10000);