Make bf_cache return ZEBRA_RES so we can check if shadow was properly
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 17 May 2005 08:50:48 +0000 (08:50 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 17 May 2005 08:50:48 +0000 (08:50 +0000)
enabled. Fixed leak that could occur if zebra_begin_trans failed.

bfile/bfile.c
bfile/mfile.c
include/idzebra/bfile.h
index/zebraapi.c

index c5de537..ab5fa6c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: bfile.c,v 1.42 2005-04-18 08:05:28 adam Exp $
+/* $Id: bfile.c,v 1.43 2005-05-17 08:50:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -99,11 +99,11 @@ static void unlink_cache (BFiles bfs)
     unlink (bfs->cache_fname);
 }
 
-void bf_cache (BFiles bfs, const char *spec)
+ZEBRA_RES bf_cache (BFiles bfs, const char *spec)
 {
     if (spec)
     {
-        yaz_log (YLOG_LOG, "enabling cache spec=%s", spec);
+        yaz_log (YLOG_LOG, "enabling shadow spec=%s", spec);
         if (!bfs->commit_area)
            bfs->commit_area = mf_init ("shadow", spec, bfs->base);
         if (bfs->commit_area)
@@ -114,9 +114,15 @@ void bf_cache (BFiles bfs, const char *spec)
             strcat (bfs->cache_fname, "/cache");
             yaz_log (YLOG_LOG, "cache_fname = %s", bfs->cache_fname);
         }
+       else
+       {
+           yaz_log(YLOG_WARN, "shadow could not be enabled");
+           return ZEBRA_FAIL;
+       }
     }
     else
         bfs->commit_area = NULL;
+    return ZEBRA_OK;
 }
 
 int bf_close (BFile bf)
index 5d86ef1..ecd795d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mfile.c,v 1.60 2005-04-15 10:47:47 adam Exp $
+/* $Id: mfile.c,v 1.61 2005-05-17 08:50:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -161,7 +161,7 @@ static zint file_position(MFile mf, zint pos, int offset)
             if (!mf->wr && errno == ENOENT && off == 0)
                 return -2;
            yaz_log (YLOG_WARN|YLOG_ERRNO, "Failed to open %s", mf->files[c].path);
-            return -1;
+           return -1;
         }
     }
     ps = pos - off;
index d1b25c1..1db5fed 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: bfile.h,v 1.4 2005-03-30 09:25:23 adam Exp $
+/* $Id: bfile.h,v 1.5 2005-05-17 08:50:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -73,7 +73,7 @@ int bf_write (BFile bf, zint no, int offset, int nbytes, const void *buf);
 
 /* bf_cache: enables bfile cache if spec is not NULL */
 YAZ_EXPORT
-void bf_cache (BFiles bfs, const char *spec);
+ZEBRA_RES bf_cache (BFiles bfs, const char *spec);
 
 /* bf_commitExists: returns 1 if commit is pending; 0 otherwise */
 YAZ_EXPORT
index 5f4a9db..8d6acb9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.c,v 1.168 2005-05-11 12:39:37 adam Exp $
+/* $Id: zebraapi.c,v 1.169 2005-05-17 08:50:49 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -268,15 +268,27 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
     
     reg->dh = data1_createx (DATA1_FLAG_XML);
     if (!reg->dh)
+    {
+       xfree(reg);
         return 0;
+    }
     reg->bfs = bfs_create (res_get (res, "register"), reg_path);
     if (!reg->bfs)
     {
         data1_destroy(reg->dh);
+       xfree(reg);
         return 0;
     }
     if (useshadow)
-        bf_cache (reg->bfs, res_get (res, "shadow"));
+    {
+        if (bf_cache (reg->bfs, res_get (res, "shadow")) == ZEBRA_FAIL)
+       {
+           bfs_destroy(reg->bfs);
+           data1_destroy(reg->dh);
+           xfree(reg);
+           return 0;
+       }
+    }
 
     getcwd(cwd, sizeof(cwd)-1);
     profilePath = res_get_def(res, "profilePath", DEFAULT_PROFILE_PATH);