1 /* gdbmclose.c - Close a previously opened dbm file. */
3 /* This file is part of GDBM, the GNU data base manager.
4 Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013 Free Software Foundation,
7 GDBM is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GDBM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
20 /* Include system configuration before all else. */
25 /* Close the dbm file and free all memory associated with the file DBF.
26 Before freeing members of DBF, check and make sure that they were
30 gdbm_close (GDBM_FILE dbf)
32 int index; /* For freeing the bucket cache. */
34 /* Make sure the database is all on disk. */
35 if (dbf->read_write != GDBM_READER)
38 /* Close the file and free all malloced memory. */
40 _gdbm_mapped_unmap(dbf);
42 if (dbf->file_locking)
44 _gdbm_unlock_file (dbf);
48 if (dbf->dir != NULL) free (dbf->dir);
50 if (dbf->bucket_cache != NULL) {
51 for (index = 0; index < dbf->cache_size; index++) {
52 if (dbf->bucket_cache[index].ca_bucket != NULL)
53 free (dbf->bucket_cache[index].ca_bucket);
54 if (dbf->bucket_cache[index].ca_data.dptr != NULL)
55 free (dbf->bucket_cache[index].ca_data.dptr);
57 free (dbf->bucket_cache);
59 if ( dbf->header != NULL ) free (dbf->header);