From 43136cc7bfb9a44db2800fdfb360e08e36e6f7c2 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 16 Aug 2010 02:56:52 +0200 Subject: Fixed error handling in httpd and commands. --- commands.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index b2c989a..d380c32 100644 --- a/commands.c +++ b/commands.c @@ -44,7 +44,8 @@ static void commands_get_raw(GSocketConnection *connection, const gchar *cmd) { struct file *f = music_find_file(path); if(f == NULL) { - g_error("couldn't find %s", path); + g_warning("couldn't find %s", path); + goto commands_get_raw_free_path; } GOutputStream *os = g_io_stream_get_output_stream((GIOStream*)connection); @@ -52,14 +53,18 @@ static void commands_get_raw(GSocketConnection *connection, const gchar *cmd) { GFileInputStream *is = g_file_read(file, NULL, &error); if(is == NULL) { - g_error(error->message); + g_warning(error->message); + g_error_free(error); + goto commands_get_raw_file_unref; } GFileInfo *fi = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, &error); if(fi == NULL) { - g_error(error->message); + g_warning(error->message); + g_error_free(error); + goto commands_get_raw_file_unref; } goffset filesize = g_file_info_get_size(fi); @@ -73,7 +78,10 @@ static void commands_get_raw(GSocketConnection *connection, const gchar *cmd) { if(g_output_stream_write_all(os, string->str, string->len, NULL, NULL, &error) == FALSE) { - g_error(error->message); + g_warning(error->message); + g_error_free(error); + g_string_free(string, TRUE); + goto commands_get_raw_file_unref; } g_string_free(string, TRUE); @@ -88,9 +96,13 @@ static void commands_get_raw(GSocketConnection *connection, const gchar *cmd) { g_debug("wrote %lu bytes of file data", size); } +commands_get_raw_file_unref: + g_object_unref(is); g_object_unref(file); +commands_get_raw_free_path: + g_free(path); } -- cgit v1.2.3