2
0
Эх сурвалжийг харах

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
Daniel-Constantin Mierla 14 жил өмнө
parent
commit
9a66840692

+ 21 - 0
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;
+	}
+}

+ 3 - 7
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 */