From cf671eb6c9749a558b55155cdd6cbb2a65703d30 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Mon, 26 Nov 2012 16:19:02 +0100 Subject: [PATCH] Fix a ressource leak Due to the ordering and multiplexing of data- and metadata handle closing in ad_close(), a datafork lock handle was not released. Releasing lock handles is now done when the logic fork counter hits zero, not when the underlying filedescriptor referencing handle count reaches zero. --- libatalk/adouble/ad_flush.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libatalk/adouble/ad_flush.c b/libatalk/adouble/ad_flush.c index 61b34f50..a18c2c47 100644 --- a/libatalk/adouble/ad_flush.c +++ b/libatalk/adouble/ad_flush.c @@ -412,11 +412,11 @@ int ad_close(struct adouble *ad, int adflags) if ((adflags & ADFLAGS_DF) && (ad_data_fileno(ad) >= 0 || ad_data_fileno(ad) == AD_SYMLINK)) { if (ad->ad_data_refcount) - ad->ad_data_refcount--; + if (--ad->ad_data_refcount == 0) + adf_lock_free(&ad->ad_data_fork); if (--ad->ad_data_fork.adf_refcount == 0) { if (ad_data_closefd(ad) < 0) err = -1; - adf_lock_free(&ad->ad_data_fork); } } @@ -427,14 +427,13 @@ int ad_close(struct adouble *ad, int adflags) if (close( ad_meta_fileno(ad)) < 0) err = -1; ad_meta_fileno(ad) = -1; - if (ad->ad_vers == AD_VERSION2) - adf_lock_free(ad->ad_mdp); } } if (adflags & ADFLAGS_RF) { if (ad->ad_reso_refcount) - ad->ad_reso_refcount--; + if (--ad->ad_reso_refcount == 0) + adf_lock_free(ad->ad_rfp); if (ad->ad_vers == AD_VERSION_EA) { if ((ad_reso_fileno(ad) != -1) && !(--ad->ad_rfp->adf_refcount)) { @@ -442,7 +441,6 @@ int ad_close(struct adouble *ad, int adflags) err = -1; ad->ad_rlen = 0; ad_reso_fileno(ad) = -1; - adf_lock_free(ad->ad_rfp); } } } -- 2.39.2