@@ -87,25 +87,25 @@ int lmdump(lmdump_mode mode, const char *file)
87
87
assert (file != NULL );
88
88
89
89
int rc ;
90
+ MDB_env * env = NULL ;
91
+ MDB_txn * txn = NULL ;
92
+ MDB_dbi dbi = 0 ;
93
+ MDB_cursor * cursor = NULL ;
90
94
91
- MDB_env * env ;
92
95
rc = mdb_env_create (& env );
93
- if (rc ) return lmdump_report_error ( rc ) ;
96
+ if (rc ) goto cleanup ;
94
97
95
98
rc = mdb_env_open (env , file , MDB_NOSUBDIR | MDB_RDONLY , 0644 );
96
- if (rc ) return lmdump_report_error ( rc ) ;
99
+ if (rc ) goto cleanup ;
97
100
98
- MDB_txn * txn ;
99
101
rc = mdb_txn_begin (env , NULL , MDB_RDONLY , & txn );
100
- if (rc ) return lmdump_report_error ( rc ) ;
102
+ if (rc ) goto cleanup ;
101
103
102
- MDB_dbi dbi ;
103
104
rc = mdb_open (txn , NULL , 0 , & dbi );
104
- if (rc ) return lmdump_report_error ( rc ) ;
105
+ if (rc ) goto cleanup ;
105
106
106
- MDB_cursor * cursor ;
107
107
rc = mdb_cursor_open (txn , dbi , & cursor );
108
- if (rc ) return lmdump_report_error ( rc ) ;
108
+ if (rc ) goto cleanup ;
109
109
110
110
MDB_val key , data ;
111
111
while ( (rc = mdb_cursor_get (cursor , & key , & data , MDB_NEXT )) == MDB_SUCCESS )
@@ -115,14 +115,16 @@ int lmdump(lmdump_mode mode, const char *file)
115
115
if (rc != MDB_NOTFOUND )
116
116
{
117
117
// At this point, not found is expected, anything else is an error
118
- return lmdump_report_error ( rc ) ;
118
+ goto cleanup ;
119
119
}
120
- mdb_cursor_close (cursor );
121
- mdb_close (env , dbi );
122
-
123
- mdb_txn_abort (txn );
124
- mdb_env_close (env );
120
+ rc = 0 ;
121
+ cleanup :
122
+ if (cursor ) mdb_cursor_close (cursor );
123
+ if (dbi ) mdb_close (env , dbi );
124
+ if (txn ) mdb_txn_abort (txn );
125
+ if (env ) mdb_env_close (env );
125
126
127
+ if (rc ) return lmdump_report_error (rc );
126
128
return 0 ;
127
129
}
128
130
0 commit comments