_alpm_handle_free: free all in-memory resources
Freeing handle resources was previously split awkwardly between _alpm_handle_free and alpm_release. This consolidates the freeing of all in-memory resources to _alpm_handle_free, leaving alpm_release as a thin wrapper that provides safety checks and frees any external resources, e.g. removing lock files. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
parent
00d2b1f902
commit
929bad61c0
2 changed files with 25 additions and 21 deletions
|
@ -93,34 +93,16 @@ cleanup:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* check current state and free all resources including storage locks */
|
||||
int SYMEXPORT alpm_release(alpm_handle_t *myhandle)
|
||||
{
|
||||
int ret = 0;
|
||||
alpm_db_t *db;
|
||||
|
||||
CHECK_HANDLE(myhandle, return -1);
|
||||
|
||||
/* close local database */
|
||||
db = myhandle->db_local;
|
||||
if(db) {
|
||||
db->ops->unregister(db);
|
||||
myhandle->db_local = NULL;
|
||||
}
|
||||
|
||||
if(alpm_unregister_all_syncdbs(myhandle) == -1) {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBCURL
|
||||
curl_multi_cleanup(myhandle->curlm);
|
||||
curl_global_cleanup();
|
||||
FREELIST(myhandle->server_errors);
|
||||
#endif
|
||||
ASSERT(myhandle->trans == NULL, RET_ERR(myhandle, ALPM_ERR_TRANS_NOT_NULL, -1));
|
||||
|
||||
_alpm_handle_unlock(myhandle);
|
||||
_alpm_handle_free(myhandle);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char SYMEXPORT *alpm_version(void)
|
||||
|
|
|
@ -48,12 +48,28 @@ alpm_handle_t *_alpm_handle_new(void)
|
|||
return handle;
|
||||
}
|
||||
|
||||
/* free all in-memory resources */
|
||||
void _alpm_handle_free(alpm_handle_t *handle)
|
||||
{
|
||||
alpm_list_t *i;
|
||||
alpm_db_t *db;
|
||||
|
||||
if(handle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* close local database */
|
||||
if((db = handle->db_local)) {
|
||||
db->ops->unregister(db);
|
||||
}
|
||||
|
||||
/* unregister all sync dbs */
|
||||
for(i = handle->dbs_sync; i; i = i->next) {
|
||||
db = i->data;
|
||||
db->ops->unregister(db);
|
||||
}
|
||||
alpm_list_free(handle->dbs_sync);
|
||||
|
||||
/* close logfile */
|
||||
if(handle->logstream) {
|
||||
fclose(handle->logstream);
|
||||
|
@ -68,6 +84,12 @@ void _alpm_handle_free(alpm_handle_t *handle)
|
|||
FREELIST(handle->known_keys);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBCURL
|
||||
curl_multi_cleanup(handle->curlm);
|
||||
curl_global_cleanup();
|
||||
FREELIST(handle->server_errors);
|
||||
#endif
|
||||
|
||||
/* free memory */
|
||||
_alpm_trans_free(handle->trans);
|
||||
FREE(handle->root);
|
||||
|
|
Loading…
Add table
Reference in a new issue