00001 /* 00002 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu> 00003 ** 00004 ** This library is free software; you can redistribute it and/or 00005 ** modify it under the terms of the GNU Library General Public 00006 ** License as published by the Free Software Foundation; either 00007 ** version 2 of the License, or (at your option) any later version. 00008 ** 00009 ** This library is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 ** Library General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU Library General Public 00015 ** License along with this library; if not, write to the Free 00016 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, 00017 ** MA 02111-1307, USA 00018 ** 00019 ** @(#)$Id: ht_free.c,v 1.4 2006/07/13 05:36:16 klmitch Exp $ 00020 */ 00028 #include <stdlib.h> 00029 00030 #include "dbprim.h" 00031 #include "dbprim_int.h" 00032 00033 RCSTAG("@(#)$Id: ht_free.c,v 1.4 2006/07/13 05:36:16 klmitch Exp $"); 00034 00035 unsigned long 00036 ht_free(hash_table_t *table) 00037 { 00038 initialize_dbpr_error_table(); /* initialize error table */ 00039 00040 if (!ht_verify(table)) /* verify argument */ 00041 return DB_ERR_BADARGS; 00042 00043 if (table->ht_flags & HASH_FLAG_FREEZE) /* don't free from frozen tables */ 00044 return DB_ERR_FROZEN; 00045 00046 if (table->ht_count) /* make sure the table's empty */ 00047 return DB_ERR_NOTEMPTY; 00048 00049 if (!table->ht_modulus && !table->ht_table) /* short-circuit */ 00050 return 0; 00051 00052 free(table->ht_table); /* free allocated memory */ 00053 00054 table->ht_modulus = 0; /* zero the table and modulus */ 00055 table->ht_rollover = 0; /* must also zero the rollover/rollunder */ 00056 table->ht_rollunder = 0; 00057 table->ht_table = 0; 00058 00059 return 0; 00060 }