Skip to content

Commit

Permalink
Convert item to GObject. Fixes #1200 double free
Browse files Browse the repository at this point in the history
  • Loading branch information
lwindolf committed Feb 4, 2023
1 parent c6ee722 commit e1d0915
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 101 deletions.
4 changes: 2 additions & 2 deletions src/feed_parser.h
@@ -1,7 +1,7 @@
/**
* @file feed_parser.h parsing of different feed formats
*
* Copyright (C) 2008-2021 Lars Windolf <lars.windolf@gmx.de>
* Copyright (C) 2008-2023 Lars Windolf <lars.windolf@gmx.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -30,7 +30,7 @@ typedef struct feedParserCtxt {
subscriptionPtr subscription; /**< the subscription the feed belongs to (optional) */
feedPtr feed; /**< the feed structure to fill */
GList *items; /**< the list of new items */
struct item *item; /**< the item currently parsed (or NULL) */
itemPtr item; /**< the item currently parsed (or NULL) */

GHashTable *tmpdata; /**< tmp data hash used during stateful parsing */

Expand Down
99 changes: 55 additions & 44 deletions src/item.c
@@ -1,7 +1,7 @@
/**
* @file item.c item handling
*
* Copyright (C) 2003-2021 Lars Windolf <lars.windolf@gmx.de>
* Copyright (C) 2003-2023 Lars Windolf <lars.windolf@gmx.de>
* Copyright (C) 2004-2006 Nathan J. Conrad <t98502@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -34,27 +34,55 @@
#include "render.h"
#include "xml.h"

itemPtr
item_new (void)
G_DEFINE_TYPE (LifereaItem, liferea_item, G_TYPE_OBJECT);

static void
liferea_item_finalize (GObject *object)
{
itemPtr item;
LifereaItem *item = LIFEREA_ITEM (object);

g_free (item->title);
g_free (item->source);
g_free (item->sourceId);
g_free (item->description);
g_free (item->commentFeedId);
g_free (item->nodeId);
g_free (item->parentNodeId);

item = g_new0 (struct item, 1);
g_assert (NULL == item->tmpdata); /* should be free after rendering */
metadata_list_free (item->metadata);
}

static void
liferea_item_class_init (LifereaItemClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);

object_class->finalize = liferea_item_finalize;
}

static void
liferea_item_init (LifereaItem *item)
{
item->popupStatus = TRUE;
}

return item;
LifereaItem *
item_new (void)
{
return LIFEREA_ITEM (g_object_new (LIFEREA_ITEM_TYPE, NULL));
}

itemPtr
LifereaItem *
item_load (gulong id)
{
return db_item_load (id);
}

itemPtr
item_copy (itemPtr item)
LifereaItem *
item_copy (LifereaItem *item)
{
itemPtr copy = item_new ();
LifereaItem *copy = item_new ();

item_set_title (copy, item->title);
item_set_source (copy, item->source);
Expand Down Expand Up @@ -84,7 +112,7 @@ item_copy (itemPtr item)
}

void
item_set_title (itemPtr item, const gchar * title)
item_set_title (LifereaItem *item, const gchar * title)
{
g_free (item->title);

Expand All @@ -95,7 +123,7 @@ item_set_title (itemPtr item, const gchar * title)
}

void
item_set_description (itemPtr item, const gchar *description)
item_set_description (LifereaItem *item, const gchar *description)
{
if (!description)
return;
Expand All @@ -109,7 +137,7 @@ item_set_description (itemPtr item, const gchar *description)
}

void
item_set_source (itemPtr item, const gchar * source)
item_set_source (LifereaItem *item, const gchar * source)
{
g_free (item->source);
if (source)
Expand All @@ -119,29 +147,29 @@ item_set_source (itemPtr item, const gchar * source)
}

void
item_set_id (itemPtr item, const gchar * id)
item_set_id (LifereaItem *item, const gchar * id)
{
g_free (item->sourceId);
item->sourceId = g_strdup (id);
}

void
item_set_time (itemPtr item, gint64 time)
item_set_time (LifereaItem *item, gint64 time)
{
item->time = time;
if (item->time > 0)
item->validTime = TRUE;
}

const gchar * item_get_id(itemPtr item) { return item->sourceId; }
const gchar * item_get_title(itemPtr item) {return item->title; }
const gchar * item_get_description(itemPtr item) { return item->description; }
const gchar * item_get_source(itemPtr item) { return item->source; }
const gchar * item_get_id(LifereaItem *item) { return item->sourceId; }
const gchar * item_get_title(LifereaItem *item) {return item->title; }
const gchar * item_get_description(LifereaItem *item) { return item->description; }
const gchar * item_get_source(LifereaItem *item) { return item->source; }

static GRegex *whitespace_strip_re = NULL;

gchar *
item_get_teaser (itemPtr item)
item_get_teaser (LifereaItem *item)
{
gchar *input, *tmpDesc;
gchar *teaser = NULL;
Expand Down Expand Up @@ -176,7 +204,7 @@ item_get_teaser (itemPtr item)
}

gchar *
item_make_link (itemPtr item)
item_make_link (LifereaItem *item)
{
const gchar *src;
gchar *link;
Expand All @@ -202,41 +230,24 @@ item_make_link (itemPtr item)
}

const gchar *
item_get_author(itemPtr item)
item_get_author(LifereaItem *item)
{
gchar *author;

author = (gchar *)metadata_list_get (item->metadata, "author");
return author;
}

void
item_unload (itemPtr item)
{
g_free (item->title);
g_free (item->source);
g_free (item->sourceId);
g_free (item->description);
g_free (item->commentFeedId);
g_free (item->nodeId);
g_free (item->parentNodeId);

g_assert (NULL == item->tmpdata); /* should be free after rendering */
metadata_list_free (item->metadata);

g_free (item);
}

const gchar *
item_get_base_url (itemPtr item)
item_get_base_url (LifereaItem *item)
{
/* item->node is always the source node for the item
never a search folder or folder */
return node_get_base_url (node_from_id (item->nodeId));
}

void
item_to_xml (itemPtr item, gpointer xmlNode)
item_to_xml (LifereaItem *item, gpointer xmlNode)
{
xmlNodePtr parentNode = (xmlNodePtr)xmlNode;
xmlNodePtr duplicatesNode;
Expand Down Expand Up @@ -293,7 +304,7 @@ item_to_xml (itemPtr item, gpointer xmlNode)
duplicates = iter = db_item_get_duplicates(item->sourceId);
while (iter) {
gulong id = GPOINTER_TO_UINT (iter->data);
itemPtr duplicate = item_load (id);
LifereaItem * duplicate = item_load (id);
if (duplicate) {
nodePtr duplicateNode = node_from_id (duplicate->nodeId);
if (duplicateNode && (item->id != duplicate->id))
Expand Down Expand Up @@ -328,7 +339,7 @@ item_to_xml (itemPtr item, gpointer xmlNode)
}

static const gchar *
item_get_text_direction (itemPtr item)
item_get_text_direction (LifereaItem *item)
{
if (item_get_title (item))
return (common_get_text_direction (item_get_title (item)));
Expand All @@ -340,7 +351,7 @@ item_get_text_direction (itemPtr item)
}

gchar *
item_render (itemPtr item, guint viewMode)
item_render (LifereaItem *item, guint viewMode)
{
renderParamPtr params;
gchar *output = NULL, *baseUrl = NULL;
Expand Down

0 comments on commit e1d0915

Please sign in to comment.