pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/41706?usp=email )


Change subject: gsmtap_util: Avoid sink_fd leak gsmtap_source_add_sinki() 
called multiple times
......................................................................

gsmtap_util: Avoid sink_fd leak gsmtap_source_add_sinki() called multiple times

gti->sink_fd could leak if  gsmtap_source_add_sink() was called multiple
times.

Also if gsmtap_source_add_sink_fd() failed, rc != -1 was returned and
hence a close() on a wrong fd would be attempted.

This commit fixes both issues, making the whole sink_fd field much more
robust.

Change-Id: I7af5a6c7d64954ee2cc013711702b846dfaa02b1
---
M src/core/gsmtap_util.c
1 file changed, 10 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/06/41706/1

diff --git a/src/core/gsmtap_util.c b/src/core/gsmtap_util.c
index f1a2abf..065dc51 100644
--- a/src/core/gsmtap_util.c
+++ b/src/core/gsmtap_util.c
@@ -436,7 +436,15 @@
  */
 int gsmtap_source_add_sink(struct gsmtap_inst *gti)
 {
-       return gti->sink_fd = gsmtap_source_add_sink_fd(gsmtap_inst_fd2(gti));
+       int rc;
+
+       if (gti->sink_fd >= 0)
+               return -EALREADY;
+
+       rc = gsmtap_source_add_sink_fd(gsmtap_inst_fd2(gti));
+       if (rc >= 0)
+               gti->sink_fd = rc;
+       return rc;
 }

 /* Registered in Osmo IO as a no-op to set the write callback. */
@@ -520,7 +528,7 @@
                close(gti->source_fd);


-       if (gti->sink_fd != -1) {
+       if (gti->sink_fd >= 0) {
                close(gti->sink_fd);
                gti->sink_fd = -1;
        }

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/41706?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I7af5a6c7d64954ee2cc013711702b846dfaa02b1
Gerrit-Change-Number: 41706
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to