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

View File

@ -99,31 +99,40 @@ mg_manga_details_recovered (MgManga *self) {
char * char *
mg_manga_get_id (MgManga *self) { mg_manga_get_id (MgManga *self) {
GValue value = G_VALUE_INIT; GValue value = G_VALUE_INIT;
char *return_value = NULL;
g_value_init (&value, G_TYPE_STRING); g_value_init (&value, G_TYPE_STRING);
g_object_get_property (G_OBJECT (self), g_object_get_property (G_OBJECT (self),
"id", "id",
&value); &value);
return g_value_dup_string (&value); return_value = g_value_dup_string (&value);
g_value_unset (&value);
return return_value;
} }
char * char *
mg_manga_get_image_url (MgManga *self) { mg_manga_get_image_url (MgManga *self) {
GValue value = G_VALUE_INIT; GValue value = G_VALUE_INIT;
char *return_value = NULL;
g_value_init (&value, G_TYPE_STRING); g_value_init (&value, G_TYPE_STRING);
g_object_get_property (G_OBJECT (self), g_object_get_property (G_OBJECT (self),
"image_url", "image_url",
&value); &value);
return g_value_dup_string (&value); return_value = g_value_dup_string (&value);
g_value_unset (&value);
return return_value;
} }
char * char *
mg_manga_get_title (MgManga *self) { mg_manga_get_title (MgManga *self) {
GValue value = G_VALUE_INIT; GValue value = G_VALUE_INIT;
char *return_value = NULL;
g_value_init (&value, G_TYPE_STRING); g_value_init (&value, G_TYPE_STRING);
g_object_get_property (G_OBJECT (self), g_object_get_property (G_OBJECT (self),
"title", "title",
&value); &value);
return g_value_dup_string (&value); return_value = g_value_dup_string (&value);
g_value_unset (&value);
return return_value;
} }
char * 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: cleanup_mg_util_xml_find_class:
if (attr) { if (attr) {

View File

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

View File

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

View File

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