aboutsummaryrefslogtreecommitdiff
path: root/src/Infobox/Wikipedia.c
diff options
context:
space:
mode:
authorfrosty <gabriel@bwaaa.monster>2026-03-15 15:18:07 -0400
committerfrosty <gabriel@bwaaa.monster>2026-03-15 15:18:07 -0400
commitb092bae97b9fd18e95c2d952732a7a4ba4b16e67 (patch)
tree46f4af868aacd662a95e26634012a85b9cbdadf8 /src/Infobox/Wikipedia.c
parent27899706fbfa1ceff1af7e3377e84748aa89fab3 (diff)
downloadomnisearch-b092bae97b9fd18e95c2d952732a7a4ba4b16e67.tar.gz
fix: free existing allocations in extract_wiki_info to prevent memory leaks
Diffstat (limited to 'src/Infobox/Wikipedia.c')
-rw-r--r--src/Infobox/Wikipedia.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Infobox/Wikipedia.c b/src/Infobox/Wikipedia.c
index b29b678..4a46b73 100644
--- a/src/Infobox/Wikipedia.c
+++ b/src/Infobox/Wikipedia.c
@@ -46,6 +46,9 @@ static void extract_wiki_info(xmlNode *node, InfoBox *info) {
if (strcmp((const char *)cur_node->name, "page") == 0) {
xmlChar *title = xmlGetProp(cur_node, (const xmlChar *)"title");
if (title) {
+ if (info->title) {
+ free(info->title);
+ }
info->title = strdup((const char *)title);
const char *base_article_url = "https://en.wikipedia.org/wiki/";
@@ -55,6 +58,9 @@ static void extract_wiki_info(xmlNode *node, InfoBox *info) {
formatted_title[i] = '_';
}
+ if (info->url) {
+ free(info->url);
+ }
info->url =
malloc(strlen(base_article_url) + strlen(formatted_title) + 1);
if (info->url) {
@@ -69,6 +75,9 @@ static void extract_wiki_info(xmlNode *node, InfoBox *info) {
if (strcmp((const char *)cur_node->name, "thumbnail") == 0) {
xmlChar *source = xmlGetProp(cur_node, (const xmlChar *)"source");
if (source) {
+ if (info->thumbnail_url) {
+ free(info->thumbnail_url);
+ }
info->thumbnail_url = strdup((const char *)source);
xmlFree(source);
}
@@ -77,6 +86,9 @@ static void extract_wiki_info(xmlNode *node, InfoBox *info) {
if (strcmp((const char *)cur_node->name, "extract") == 0) {
xmlChar *content = xmlNodeGetContent(cur_node);
if (content) {
+ if (info->extract) {
+ free(info->extract);
+ }
info->extract = strdup((const char *)content);
shorten_summary(&(info->extract), 300);