Fixed bug #794: Excessive memory when searching the LoC only.
[pazpar2-moved-to-github.git] / src / pazpar2.c
index 3482d83..cb6a384 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pazpar2.c,v 1.11 2007-01-04 07:27:29 adam Exp $ */;
+/* $Id: pazpar2.c,v 1.15 2007-01-05 20:33:05 adam Exp $ */;
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -11,6 +11,7 @@
 #include <ctype.h>
 #include <assert.h>
 
+#include <yaz/marcdisp.h>
 #include <yaz/comstack.h>
 #include <yaz/tcpip.h>
 #include <yaz/proto.h>
@@ -430,6 +431,7 @@ static struct record *ingest_record(struct client *cl, Z_External *rec)
     if (!(mergekey = xmlGetProp(root, "mergekey")))
     {
         yaz_log(YLOG_WARN, "No mergekey found in record");
+        xmlFreeDoc(xdoc);
         return 0;
     }
 
@@ -445,6 +447,12 @@ static struct record *ingest_record(struct client *cl, Z_External *rec)
     res->merge_key = normalize_mergekey(mergekey_norm);
 
     head = reclist_insert(se->reclist, res);
+    if (!head)
+    {
+        /* no room for record */
+        xmlFreeDoc(xdoc);
+        return 0;
+    }
     relevance_newrec(se->relevance, head);
 
     for (n = root->children; n; n = n->next)
@@ -455,21 +463,28 @@ static struct record *ingest_record(struct client *cl, Z_External *rec)
         {
             xmlChar *type = xmlGetProp(n, "type");
             xmlChar *value = xmlNodeListGetString(xdoc, n->children, 0);
-            add_facet(se, type, value);
-            relevance_countwords(se->relevance, head, value, 1);
+            if (type && value)
+            {
+                add_facet(se, type, value);
+                relevance_countwords(se->relevance, head, value, 1);
+            }
             xmlFree(type);
             xmlFree(value);
         }
         else if (!strcmp(n->name, "metadata"))
         {
-            xmlChar *type = xmlGetProp(n, "type"), *value;
-            if (!strcmp(type, "title"))
-                res->title = nmem_strdup(se->nmem,
-                        value = xmlNodeListGetString(xdoc, n->children, 0));
-
-            relevance_countwords(se->relevance, head, value, 4);
+            xmlChar *type = xmlGetProp(n, "type");
+            if (type && !strcmp(type, "title"))
+            {
+                xmlChar *value = xmlNodeListGetString(xdoc, n->children, 0);
+                if (value)
+                {
+                    res->title = nmem_strdup(se->nmem, value);
+                    relevance_countwords(se->relevance, head, value, 4);
+                    xmlFree(value);
+                }
+            }
             xmlFree(type);
-            xmlFree(value);
         }
         else
             yaz_log(YLOG_WARN, "Unexpected element %s in internal record", n->name);
@@ -1152,9 +1167,7 @@ struct termlist_score **termlist(struct session *s, const char *name, int *num)
     return 0;
 }
 
-#ifdef REPORT_NMEM
-// conditional compilation by SH: This lead to a warning with currently installed
-// YAZ header files on us1
+#ifdef MISSING_HEADERS
 void report_nmem_stats(void)
 {
     size_t in_use, is_free;