From c4f5c81c1fef61826e2ca7815d5f427a0a82b8e7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 17 May 2005 08:50:48 +0000 Subject: [PATCH] Make bf_cache return ZEBRA_RES so we can check if shadow was properly enabled. Fixed leak that could occur if zebra_begin_trans failed. --- bfile/bfile.c | 12 +++++++++--- bfile/mfile.c | 4 ++-- include/idzebra/bfile.h | 4 ++-- index/zebraapi.c | 16 ++++++++++++++-- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/bfile/bfile.c b/bfile/bfile.c index c5de537..ab5fa6c 100644 --- a/bfile/bfile.c +++ b/bfile/bfile.c @@ -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) diff --git a/bfile/mfile.c b/bfile/mfile.c index 5d86ef1..ecd795d 100644 --- a/bfile/mfile.c +++ b/bfile/mfile.c @@ -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; diff --git a/include/idzebra/bfile.h b/include/idzebra/bfile.h index d1b25c1..1db5fed 100644 --- a/include/idzebra/bfile.h +++ b/include/idzebra/bfile.h @@ -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 diff --git a/index/zebraapi.c b/index/zebraapi.c index 5f4a9db..8d6acb9 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -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); -- 1.7.10.4