[sr-dev] git:3.1: kcore: supported header exports the free function in parsed structure

Daniel-Constantin Mierla miconda at gmail.com
Sun Feb 27 23:45:35 CET 2011


Module: sip-router
Branch: 3.1
Commit: 7310ba9d6c808dc932fe1e925b9e36e57f6b473e
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=7310ba9d6c808dc932fe1e925b9e36e57f6b473e

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Sun Feb 27 16:43:06 2011 +0100

kcore: supported header exports the free function in parsed structure

- parsing the supported header creates a structure allocated in PKG, now
  it exports the function to free it in order to be used when cleaning
  the SIP message structure
- this fixes a memory leak when parsing the header
- reported and troubleshooted by Bayan Towfiq
(cherry picked from commit 9a668406925abf19cbae62c98a12b86f4c045b34)

---

 lib/kcore/parse_supported.c |   21 +++++++++++++++++++++
 lib/kcore/parse_supported.h |   10 +++-------
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/lib/kcore/parse_supported.c b/lib/kcore/parse_supported.c
index 8720397..8c81cfb 100644
--- a/lib/kcore/parse_supported.c
+++ b/lib/kcore/parse_supported.c
@@ -112,6 +112,17 @@ static inline int parse_supported_body(str *body, unsigned int *sup)
 	return 0;
 }
 
+
+/**
+ * wrapper to free the content of parsed supported header
+ */
+void hf_free_supported(void *parsed)
+{
+	struct supported_body *sb;
+	sb = (struct supported_body*)parsed;
+	free_supported(&sb);
+}
+
 /*!
  * Parse all Supported headers
  */
@@ -144,6 +155,7 @@ int parse_supported( struct sip_msg *msg)
 		}
 
 		parse_supported_body(&(hdr->body), &(sb->supported));
+		sb->hfree = hf_free_supported;
 		sb->supported_all = 0;
 		hdr->parsed = (void*)sb;
 		supported |= sb->supported;
@@ -153,3 +165,12 @@ int parse_supported( struct sip_msg *msg)
 		supported;
 	return 0;
 }
+
+/* free supported header structure */
+void free_supported(struct supported_body **sb)
+{
+	if (sb && *sb) {
+		pkg_free(*sb);
+		*sb = 0;
+	}
+}
diff --git a/lib/kcore/parse_supported.h b/lib/kcore/parse_supported.h
index 126f56e..55f04f8 100644
--- a/lib/kcore/parse_supported.h
+++ b/lib/kcore/parse_supported.h
@@ -36,6 +36,7 @@
 #define PARSE_SUPPORTED_H
 
 #include "../../parser/msg_parser.h"
+#include "../../parser/hf.h"
 #include "../../mem/mem.h"
 
 
@@ -64,6 +65,7 @@
 
 
 struct supported_body {
+	hf_parsed_free_f hfree;        /* function to free the content */
 	unsigned int supported;        /* supported mask for the current hdr */
 	unsigned int supported_all;    /* suppoted mask for the all "supported" hdr
 	                                *  - it's set only for the first hdr in 
@@ -77,12 +79,6 @@ struct supported_body {
 int parse_supported( struct sip_msg *msg);
 
 
-static inline void free_supported(struct supported_body **sb)
-{
-	if (sb && *sb) {
-		pkg_free(*sb);
-		*sb = 0;
-	}
-}
+void free_supported(struct supported_body **sb);
 
 #endif /* PARSE_SUPPORTED_H */




More information about the sr-dev mailing list