Module: sip-router Branch: andrei/tcp_tls_changes Commit: e0726eab5ea489c8882a05673fe5b5016e7ab7ce URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e0726eab...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Fri May 28 12:30:39 2010 +0200
core: get_abs_pathname() uses now pkg_malloc()
get_abs_pathname() used libc malloc() instead of pkg_malloc(), making it difficult to know which free to use in fixups.
---
cfg_parser.c | 4 ++-- ut.c | 35 ++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/cfg_parser.c b/cfg_parser.c index 8a2c4e4..0827939 100644 --- a/cfg_parser.c +++ b/cfg_parser.c @@ -640,7 +640,7 @@ cfg_parser_t* cfg_parser_init(str* filename) goto error; }
- free(pathname); + pkg_free(pathname);
st->file = base; st->line = 1; @@ -653,7 +653,7 @@ cfg_parser_t* cfg_parser_init(str* filename) pkg_free(st); } if (base) pkg_free(base); - if (pathname) free(pathname); + if (pathname) pkg_free(pathname); return NULL; }
diff --git a/ut.c b/ut.c index e323071..3a2e9ec 100644 --- a/ut.c +++ b/ut.c @@ -29,11 +29,10 @@ */
-/*! - * \file - * \brief SIP-router core :: - * \ingroup core - * Module: \ref core +/** various utility functions. + * @file ut.c + * @ingroup core + * Module: @ref core */
#include <sys/types.h> @@ -215,6 +214,16 @@ unsigned int get_sys_version(int* major, int* minor, int* minor2) }
+ +/** transform a relative pathname into an absolute one. + * @param base - base file, used to extract the absolute path prefix. + * Might be NULL, in which case the path of the ser.cfg is + * used. + * @param file - file path to be transformed. If it's already absolute + * (starts with '/') is left alone. If not the result will + * be `dirname base`/file. + * @return pkg allocated asciiz string or 0 on error. + */ char* get_abs_pathname(str* base, str* file) { str ser_cfg; @@ -241,8 +250,8 @@ char* get_abs_pathname(str* base, str* file) if (file->s[0] == '/') { /* This is an absolute pathname, make a zero terminated * copy and use it as it is */ - if ((res = malloc(file->len+1)) == NULL) { - ERR("get_abs_pathname: No memory left (malloc failed)\n"); + if ((res = pkg_malloc(file->len+1)) == NULL) { + ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n"); } memcpy(res, file->s, file->len); res[file->len]=0; @@ -251,8 +260,8 @@ char* get_abs_pathname(str* base, str* file) * to the location of the base file */ /* Make a copy, function dirname may modify the string */ - if ((buf = malloc(base->len+1)) == NULL) { - ERR("get_abs_pathname: No memory left (malloc failed)\n"); + if ((buf = pkg_malloc(base->len+1)) == NULL) { + ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n"); return NULL; } memcpy(buf, base->s, base->len); @@ -260,16 +269,16 @@ char* get_abs_pathname(str* base, str* file) dir = dirname(buf); len = strlen(dir); - if ((res = malloc(len + 1 + file->len + 1)) == NULL) { - ERR("get_abs_pathname: No memory left (malloc failed)\n"); - free(buf); + if ((res = pkg_malloc(len + 1 + file->len + 1)) == NULL) { + ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n"); + pkg_free(buf); return NULL; } memcpy(res, dir, len); res[len] = '/'; memcpy(res + len + 1, file->s, file->len); res[len + 1 + file->len] = '\0'; - free(buf); + pkg_free(buf); } return res; }