lib/hdb/db3.c:DB_open() needs to DB_close() more
Without this the KDC can trip the assert in DB_open().
This commit is contained in:
@@ -62,20 +62,20 @@ DB_close(krb5_context context, HDB *db)
|
|||||||
{
|
{
|
||||||
DB3_HDB *db3 = (DB3_HDB *)db;
|
DB3_HDB *db3 = (DB3_HDB *)db;
|
||||||
DB *d = (DB*)db->hdb_db;
|
DB *d = (DB*)db->hdb_db;
|
||||||
DBC *dbcp;
|
DBC *dbcp = (DBC*)db->hdb_dbc;
|
||||||
|
|
||||||
heim_assert(d != 0, "Closing already closed HDB");
|
heim_assert(d != 0, "Closing already closed HDB");
|
||||||
|
|
||||||
dbcp = (DBC*)db->hdb_dbc;
|
if (dbcp != NULL)
|
||||||
(*dbcp->c_close)(dbcp);
|
dbcp->c_close(dbcp);
|
||||||
db->hdb_dbc = 0;
|
if (d != NULL)
|
||||||
(*d->close)(d, 0);
|
d->close(d, 0);
|
||||||
db->hdb_db = 0;
|
if (db3->lock_fd >= 0)
|
||||||
|
|
||||||
if (db3->lock_fd >= 0) {
|
|
||||||
close(db3->lock_fd);
|
close(db3->lock_fd);
|
||||||
db3->lock_fd = -1;
|
|
||||||
}
|
db3->lock_fd = -1;
|
||||||
|
db->hdb_dbc = 0;
|
||||||
|
db->hdb_db = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -278,6 +278,7 @@ _open_db(DB *d, char *fn, int myflags, int flags, mode_t mode, int *fd)
|
|||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
ret = errno;
|
ret = errno;
|
||||||
close(*fd);
|
close(*fd);
|
||||||
|
*fd = -1;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,8 +290,10 @@ _open_db(DB *d, char *fn, int myflags, int flags, mode_t mode, int *fd)
|
|||||||
ret = (*d->open)(d, fn, NULL, DB_BTREE, myflags, mode);
|
ret = (*d->open)(d, fn, NULL, DB_BTREE, myflags, mode);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0) {
|
||||||
close(*fd);
|
close(*fd);
|
||||||
|
*fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -333,15 +336,17 @@ DB_open(krb5_context context, HDB *db, int flags, mode_t mode)
|
|||||||
}
|
}
|
||||||
db->hdb_db = d;
|
db->hdb_db = d;
|
||||||
|
|
||||||
|
/* From here on out always DB_close() before returning on error */
|
||||||
|
|
||||||
ret = _open_db(d, fn, myflags, flags, mode, &db3->lock_fd);
|
ret = _open_db(d, fn, myflags, flags, mode, &db3->lock_fd);
|
||||||
free(fn);
|
free(fn);
|
||||||
if (ret == ENOENT) {
|
if (ret == ENOENT) {
|
||||||
/* try to open without .db extension */
|
/* try to open without .db extension */
|
||||||
ret = _open_db(d, db->hdb_name, myflags, flags,
|
ret = _open_db(d, db->hdb_name, myflags, flags, mode, &db3->lock_fd);
|
||||||
mode, &db3->lock_fd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
DB_close(context, db);
|
||||||
krb5_set_error_message(context, ret, "opening %s: %s",
|
krb5_set_error_message(context, ret, "opening %s: %s",
|
||||||
db->hdb_name, strerror(ret));
|
db->hdb_name, strerror(ret));
|
||||||
return ret;
|
return ret;
|
||||||
@@ -353,6 +358,7 @@ DB_open(krb5_context context, HDB *db, int flags, mode_t mode)
|
|||||||
ret = (*d->cursor)(d, NULL, &dbc, DB_CURSOR_BULK);
|
ret = (*d->cursor)(d, NULL, &dbc, DB_CURSOR_BULK);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
DB_close(context, db);
|
||||||
krb5_set_error_message(context, ret, "d->cursor: %s", strerror(ret));
|
krb5_set_error_message(context, ret, "d->cursor: %s", strerror(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user