Browse Source

app_perl: use local buffer to print dynamic string in pv_sprintf()

- avoid pkg malloc for temporary need
- fix leak in case of fmt parse error, discovered on a report by Dragos
  Oancea
Daniel-Constantin Mierla 12 years ago
parent
commit
1c3e761fbd
1 changed files with 1 additions and 6 deletions
  1. 1 6
      modules/app_perl/kamailioxs.xs

+ 1 - 6
modules/app_perl/kamailioxs.xs

@@ -362,15 +362,11 @@ static inline int rewrite_ruri(struct sip_msg* _m, char* _s)
  */
 char *pv_sprintf(struct sip_msg *m, char *fmt) {
 	int buf_size = 4096;
+	char out[4096];
 	pv_elem_t *model;
 	str s;
-	char *out = (char *)pkg_malloc(buf_size);
 	char *ret = NULL;
 
-	if (!out) {
-		LM_ERR("pv_sprintf: Memory exhausted!\n");
-		return NULL;
-	}
 
 	s.s = fmt; s.len = strlen(s.s);
 	if(pv_parse_format(&s, &model) < 0) {
@@ -386,7 +382,6 @@ char *pv_sprintf(struct sip_msg *m, char *fmt) {
 	}
 
 	pv_elem_free_all(model);
-	pkg_free(out);
 
 	return ret;
 }