mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix a bunch of memory allocation errors found by clang static analysis.
This commit is contained in:
@@ -378,6 +378,7 @@ GncXmlBackend::write_to_file (bool make_backup)
|
||||
|
||||
if (!mktemp (tmp_name))
|
||||
{
|
||||
g_free (tmp_name);
|
||||
set_error(ERR_BACKEND_MISC);
|
||||
set_message("Failed to make temp file");
|
||||
LEAVE ("");
|
||||
@@ -388,6 +389,7 @@ GncXmlBackend::write_to_file (bool make_backup)
|
||||
{
|
||||
if (!backup_file ())
|
||||
{
|
||||
g_free (tmp_name);
|
||||
LEAVE ("");
|
||||
return FALSE;
|
||||
}
|
||||
@@ -513,6 +515,7 @@ GncXmlBackend::write_to_file (bool make_backup)
|
||||
LEAVE ("");
|
||||
return FALSE;
|
||||
}
|
||||
g_free (tmp_name);
|
||||
LEAVE ("");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -765,49 +765,42 @@ kvp_frame_slot_end_handler (gpointer data_for_children,
|
||||
{
|
||||
KvpFrame* f = (KvpFrame*) parent_data;
|
||||
GSList* lp;
|
||||
guint64 key_node_count;
|
||||
gboolean first = TRUE;
|
||||
gchar* key = NULL;
|
||||
sixtp_child_result* value_cr = NULL;
|
||||
KvpValue* value = NULL;
|
||||
gboolean delete_value = FALSE;
|
||||
|
||||
sixtp_child_result *cr1 = NULL, *cr2 = NULL, *cr = NULL;
|
||||
g_return_val_if_fail (f, FALSE);
|
||||
|
||||
if (g_slist_length (data_from_children) != 2) return (FALSE);
|
||||
|
||||
/* check to see that we got exactly one <key> node */
|
||||
lp = data_from_children;
|
||||
key_node_count = 0;
|
||||
for (lp = data_from_children; lp; lp = lp->next)
|
||||
cr1 = (sixtp_child_result*)data_from_children->data;
|
||||
cr2 = (sixtp_child_result*)data_from_children->next->data;
|
||||
|
||||
if (is_child_result_from_node_named(cr1, "k"))
|
||||
{
|
||||
sixtp_child_result* cr = (sixtp_child_result*) lp->data;
|
||||
|
||||
if (is_child_result_from_node_named (cr, "k"))
|
||||
{
|
||||
key = (char*) cr->data;
|
||||
key_node_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_child_result_from_node_named (cr, "frame"))
|
||||
{
|
||||
KvpFrame* frame = static_cast<KvpFrame*> (cr->data);
|
||||
value = new KvpValue {frame};
|
||||
delete_value = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = static_cast<KvpValue*> (cr->data);
|
||||
delete_value = FALSE;
|
||||
}
|
||||
|
||||
value_cr = cr;
|
||||
}
|
||||
key = (char*)cr1->data;
|
||||
cr = cr2;
|
||||
}
|
||||
|
||||
if (key_node_count != 1) return (FALSE);
|
||||
|
||||
value_cr->should_cleanup = TRUE;
|
||||
else if (is_child_result_from_node_named(cr2, "k"))
|
||||
{
|
||||
key = (char*)cr2->data;
|
||||
cr = cr1;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
if (is_child_result_from_node_named (cr, "frame"))
|
||||
{
|
||||
KvpFrame* frame = static_cast<KvpFrame*> (cr->data);
|
||||
value = new KvpValue {frame};
|
||||
delete_value = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = static_cast<KvpValue*> (cr->data);
|
||||
delete_value = FALSE;
|
||||
}
|
||||
|
||||
f->set ({key}, value);
|
||||
if (delete_value)
|
||||
delete value;
|
||||
|
||||
@@ -1868,6 +1868,7 @@ gnc_xml2_find_ambiguous (const gchar* filename, GList* encodings,
|
||||
if (iconv_item->iconv == (GIConv) - 1)
|
||||
{
|
||||
PWARN ("Unable to open IConv conversion descriptor for '%s'", enc);
|
||||
g_free (iconv_item);
|
||||
goto cleanup_find_ambs;
|
||||
}
|
||||
else
|
||||
@@ -2176,7 +2177,8 @@ gnc_xml2_parse_with_subst (GncXmlBackend* xml_be, QofBook* book, GHashTable* sub
|
||||
success = qof_session_load_from_xml_file_v2_full (
|
||||
xml_be, book, (sixtp_push_handler) parse_with_subst_push_handler,
|
||||
push_data, GNC_BOOK_XML2_FILE);
|
||||
|
||||
g_free (push_data);
|
||||
|
||||
if (success)
|
||||
qof_instance_set_dirty (QOF_INSTANCE (book));
|
||||
|
||||
|
||||
@@ -267,20 +267,22 @@ sixtp_destroy_child (gpointer key, gpointer value, gpointer user_data)
|
||||
gpointer lookup_value;
|
||||
|
||||
g_debug ("Killing sixtp child under key <%s>", key ? (char*) key : "(null)");
|
||||
g_free (key);
|
||||
|
||||
if (!corpses)
|
||||
{
|
||||
g_critical ("no corpses in sixtp_destroy_child <%s>",
|
||||
key ? (char*) key : "(null)");
|
||||
g_free (key);
|
||||
return;
|
||||
}
|
||||
if (!child)
|
||||
{
|
||||
g_critical ("no child in sixtp_destroy_child <%s>",
|
||||
key ? (char*) key : "");
|
||||
g_free (key);
|
||||
return;
|
||||
}
|
||||
g_free (key);
|
||||
|
||||
if (!g_hash_table_lookup_extended (corpses, (gconstpointer) child,
|
||||
&lookup_key, &lookup_value))
|
||||
|
||||
Reference in New Issue
Block a user