aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Gaignard <benjamin.gaignard@linaro.org>2015-10-30 16:09:17 +0100
committerBenjamin Gaignard <benjamin.gaignard@linaro.org>2015-10-30 16:09:17 +0100
commit24011bdc6663bf727affadb6caa7c7f2ac49ef39 (patch)
treef243a5066402242d9a615e2cb3fdb8f82b332344
parent66f990435773a6b09581d415842ac6f6a73c6d13 (diff)
downloadlibsmaf-24011bdc6663bf727affadb6caa7c7f2ac49ef39.tar.gz
fix open/close refcount issue
Signed-off-by: Jean-Christophe Trotin <jean-christophe.trotin@st.com>
-rw-r--r--lib/libsmaf.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/libsmaf.c b/lib/libsmaf.c
index 3584e54..ee2ba81 100644
--- a/lib/libsmaf.c
+++ b/lib/libsmaf.c
@@ -41,28 +41,28 @@ static int smaf_fd = -1;
int smaf_open(void)
{
if (open_count)
- return 0;
+ goto add;
smaf_fd = open(SMAF_DEV, O_RDWR, 0);
if (smaf_fd == -1)
return -1;
+add:
open_count++;
return 0;
}
void smaf_close(void)
{
- if (open_count)
- open_count--;
-
- if (!open_count) {
- if (smaf_fd != -1)
- close(smaf_fd);
-
- smaf_fd = -1;
- }
+ if (open_count) {
+ if (!--open_count) {
+ if (smaf_fd != -1)
+ close(smaf_fd);
+
+ smaf_fd = -1;
+ }
+ }
}
int smaf_create_buffer(unsigned int length, unsigned int flags, char *name, int *fd)