Browse code

registrar: Fix memory leak around path and outbound header parsing

- Fix leak of parsed URI and URI parameters during a call to save()
(cherry picked from commit 56c880120c07443eceb732117f0f1aa3558dcfe5)

Hugh Waite authored on 09/12/2014 19:05:31
Showing 2 changed files
... ...
@@ -96,6 +96,8 @@ int build_path_vector(struct sip_msg *_m, str *path, str *received)
96 96
 				LM_ERR("failed to parse parameters of first hop\n");
97 97
 				goto error;
98 98
 			}
99
+			/* Not interested in param body - just the hooks */
100
+			free_params(params);
99 101
 
100 102
 			if (hooks.contact.received) {
101 103
 			        uri_str.s = uri_buf;
... ...
@@ -107,14 +109,6 @@ int build_path_vector(struct sip_msg *_m, str *path, str *received)
107 107
 				*received = uri_str;
108 108
 				LM_DBG("received is <%.*s>\n", received->len, received->s);
109 109
 			}
110
-				
111
-			/*for (;params; params = params->next) {
112
-				if (params->type == P_RECEIVED) {
113
-					*received = hooks.contact.received->body;
114
-					break;
115
-				}
116
-			}*/
117
-			free_params(params);
118 110
 		}
119 111
 		free_rr(&route);
120 112
 	}
... ...
@@ -923,17 +923,21 @@ int save(struct sip_msg* _m, udomain_t* _d, int _cflags, str *_uri)
923 923
 			}
924 924
 			if (parse_uri(route->nameaddr.uri.s, route->nameaddr.uri.len, &puri) < 0) {
925 925
 				LM_ERR("Failed to parse Path: URI\n");
926
+				free_rr(&route);
926 927
 				goto error;
927 928
 			}
928 929
 			if (parse_params(&puri.params, CLASS_URI, &hooks, &params) != 0) {
929 930
 				LM_ERR("Failed to parse Path: URI parameters\n");
931
+				free_rr(&route);
930 932
 				goto error;
931 933
 			}
934
+			/* Not interested in param body - just the hooks */
935
+			free_params(params);
932 936
 			if (!hooks.uri.ob) {
933 937
 				/* No ;ob parameter to top Path: URI - no outbound */
934 938
 				use_ob = 0;
935 939
 			}
936
-
940
+			free_rr(&route);
937 941
 		} else {
938 942
 			/* No Path: header - no outbound */
939 943
 			use_ob = 0;