c2681ed
commit f679bf70e8293021c4d42bdd331d0184d0ed140e
c2681ed
Author: John Ralls <jralls@ceridwen.us>
c2681ed
Date:   Tue May 10 13:28:58 2016 -0700
c2681ed
c2681ed
    Bug 766028 - crash on manual addition of price entry in Price Editor
c2681ed
    
c2681ed
    gnc_pricedb_remove_price invalidates db->commodity_hash so removing the
c2681ed
    old price needs to be done before it's retrieved.
c2681ed
c2681ed
diff --git a/src/engine/gnc-pricedb.c b/src/engine/gnc-pricedb.c
c2681ed
index 790cf32..f777f5f 100644
c2681ed
--- a/src/engine/gnc-pricedb.c
c2681ed
+++ b/src/engine/gnc-pricedb.c
c2681ed
@@ -1047,6 +1047,22 @@ add_price(GNCPriceDB *db, GNCPrice *p)
c2681ed
         LEAVE ("no commodity hash found ");
c2681ed
         return FALSE;
c2681ed
     }
c2681ed
+/* Check for an existing price on the same day. If there is no existing price,
c2681ed
+ * add this one. If this price is of equal or better precedence than the old
c2681ed
+ * one, copy this one over the old one.
c2681ed
+ */
c2681ed
+    old_price = gnc_pricedb_lookup_day (db, p->commodity, p->currency,
c2681ed
+                                        p->tmspec);
c2681ed
+    if (!db->bulk_update && old_price != NULL)
c2681ed
+    {
c2681ed
+        if (p->source > old_price->source)
c2681ed
+        {
c2681ed
+            gnc_price_unref(p);
c2681ed
+            LEAVE ("Better price already in DB.");
c2681ed
+            return FALSE;
c2681ed
+        }
c2681ed
+        gnc_pricedb_remove_price(db, old_price);
c2681ed
+    }
c2681ed
 
c2681ed
     currency_hash = g_hash_table_lookup(db->commodity_hash, commodity);
c2681ed
     if (!currency_hash)
c2681ed
@@ -1068,22 +1084,6 @@ add_price(GNCPriceDB *db, GNCPrice *p)
c2681ed
         return FALSE;
c2681ed
     }
c2681ed
 
c2681ed
-/* Check for an existing price on the same day. If there is no existing price,
c2681ed
- * add this one. If this price is of equal or better precedence than the old
c2681ed
- * one, copy this one over the old one.
c2681ed
- */
c2681ed
-    old_price = gnc_pricedb_lookup_day (db, p->commodity, p->currency,
c2681ed
-                                        p->tmspec);
c2681ed
-    if (!db->bulk_update && old_price != NULL)
c2681ed
-    {
c2681ed
-        if (p->source > old_price->source)
c2681ed
-        {
c2681ed
-            gnc_price_unref(p);
c2681ed
-            LEAVE ("Better price already in DB.");
c2681ed
-            return FALSE;
c2681ed
-        }
c2681ed
-        gnc_pricedb_remove_price(db, old_price);
c2681ed
-    }
c2681ed
     g_hash_table_insert(currency_hash, currency, price_list);
c2681ed
     p->db = db;
c2681ed