Memory cleanup.

This commit is contained in:
sergiotarxz 2021-11-20 17:24:24 +01:00
parent d988143e76
commit 793726aa7c
6 changed files with 43 additions and 13 deletions

View File

@ -267,7 +267,9 @@ mg_backend_readmng_retrieve_manga_details (MgBackendReadmng *self,
mg_manga_set_chapter_list (manga, manga_chapters);
mg_manga_details_recovered (manga);
cleanup_mg_backend_readmng_retrieve_manga_details:
if (movie_detail) {
g_free (movie_detail);
}
}
static GListStore *
@ -369,10 +371,12 @@ mg_backend_readmng_fetch_xml_details (MgBackendReadmng *self,
request_url_len = snprintf ( NULL, 0, "%s/%s/", self->base_url, manga_id);
request_url = mg_util_string_alloc_string (string_util, request_url_len);
snprintf ( request_url, request_url_len+1, "%s/%s/", self->base_url, manga_id);
g_free (manga_id);
char *html_response = mg_util_soup_get_request (util_soup,
request_url, &response_len);
g_object_unref (util_soup);
g_clear_object (&util_soup);
g_clear_object (&string_util);
return htmlReadMemory (html_response, response_len, NULL, NULL,
HTML_PARSE_RECOVER | HTML_PARSE_NODEFDTD
| HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING );
@ -475,7 +479,9 @@ mg_backend_readmng_retrieve_slides (MgBackendReadmng *self, const xmlDocPtr html
xmlXPathFreeObject(xpath_result);
}
cleanup_mg_backend_readmng_retrieve_slides:
if (nodes) {
g_free (nodes);
}
return slides;
}
@ -483,10 +489,16 @@ static xmlNodePtr
mg_backend_readmng_retrieve_thumbnail_from_li (MgBackendReadmng *self, xmlNodePtr current_li) {
size_t thumbnail_len = 0;
MgUtilXML *xml_utils = self->xml_utils;
xmlNodePtr return_value = NULL;
xmlNodePtr *thumbnail = mg_util_xml_find_class (xml_utils, current_li, "thumbnail",
&thumbnail_len, NULL, 1);
if (thumbnail_len) return thumbnail[0];
return NULL;
if (!thumbnail_len) goto cleanup_mg_backend_retrieve_thumbnail_from_li;
return_value = thumbnail[0];
cleanup_mg_backend_retrieve_thumbnail_from_li:
if (thumbnail) {
g_free (thumbnail);
}
return return_value;
}
static xmlNodePtr
@ -535,6 +547,13 @@ mg_backend_readmng_extract_manga_info_from_current_li (MgBackendReadmng *self,
mg_manga_new (mg_util_xml_get_attr (xml_utils, img, "src"),
(char *)xmlNodeGetContent (title), id_manga));
}
if (thumbnail) {
xmlFreeNode (thumbnail);
}
if (title) {
xmlFreeNode (title);
}
}
static xmlNodePtr

View File

@ -99,31 +99,40 @@ mg_manga_details_recovered (MgManga *self) {
char *
mg_manga_get_id (MgManga *self) {
GValue value = G_VALUE_INIT;
char *return_value = NULL;
g_value_init (&value, G_TYPE_STRING);
g_object_get_property (G_OBJECT (self),
"id",
&value);
return g_value_dup_string (&value);
return_value = g_value_dup_string (&value);
g_value_unset (&value);
return return_value;
}
char *
mg_manga_get_image_url (MgManga *self) {
GValue value = G_VALUE_INIT;
char *return_value = NULL;
g_value_init (&value, G_TYPE_STRING);
g_object_get_property (G_OBJECT (self),
"image_url",
&value);
return g_value_dup_string (&value);
return_value = g_value_dup_string (&value);
g_value_unset (&value);
return return_value;
}
char *
mg_manga_get_title (MgManga *self) {
GValue value = G_VALUE_INIT;
char *return_value = NULL;
g_value_init (&value, G_TYPE_STRING);
g_object_get_property (G_OBJECT (self),
"title",
&value);
return g_value_dup_string (&value);
return_value = g_value_dup_string (&value);
g_value_unset (&value);
return return_value;
}
char *

View File

@ -57,6 +57,8 @@ mg_util_xml_find_class (MgUtilXML *self, xmlNodePtr node, char *class,
}
}
}
g_free (attr);
attr = NULL;
}
cleanup_mg_util_xml_find_class:
if (attr) {

View File

@ -108,5 +108,6 @@ create_detail_view (MgManga *manga, AdwLeaflet *views_leaflet) {
g_free (manga_title_text);
g_free (title_text);
g_free (description_text);
g_clear_object (&xml_util);
return detail_view;
}

View File

@ -87,12 +87,10 @@ int
main_view_run (int argc,
char **argv)
{
AdwApplication *app;
int status;
app = adw_application_new ("org.mangareader", G_APPLICATION_FLAGS_NONE);
AdwApplication *app = adw_application_new ("me.sergiotarxz.mangareader", G_APPLICATION_FLAGS_NONE);
int status = 0;
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
g_clear_object (&app);
return status;
}

View File

@ -35,5 +35,6 @@ create_picture_from_url (char *url, gint picture_height) {
cleanup_create_picture_from_url:
g_free (downloaded_image);
g_clear_object (&util_soup);
return picture;
}