Avoid SEGV for cmd=record in case of no search
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 21 Jan 2011 11:32:38 +0000 (12:32 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 21 Jan 2011 11:33:48 +0000 (12:33 +0100)
src/session.c

index 93b25ce..04807a8 100644 (file)
@@ -844,22 +844,25 @@ struct record_cluster *show_single_start(struct session *se, const char *id,
                                          struct record_cluster **prev_r,
                                          struct record_cluster **next_r)
 {
-    struct record_cluster *r;
+    struct record_cluster *r = 0;
 
     session_enter(se);
-    reclist_enter(se->reclist);
     *prev_r = 0;
     *next_r = 0;
-    while ((r = reclist_read_record(se->reclist)))
+    if (se->reclist)
     {
-        if (!strcmp(r->recid, id))
+        reclist_enter(se->reclist);
+        while ((r = reclist_read_record(se->reclist)))
         {
-            *next_r = reclist_read_record(se->reclist);
-            break;
+            if (!strcmp(r->recid, id))
+            {
+                *next_r = reclist_read_record(se->reclist);
+                break;
+            }
+            *prev_r = r;
         }
-        *prev_r = r;
+        reclist_leave(se->reclist);
     }
-    reclist_leave(se->reclist);
     if (!r)
         session_leave(se);
     return r;