Browse code

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.

Andrei Pelinescu-Onciul authored on 28/05/2010 10:30:39
Showing 2 changed files
... ...
@@ -640,7 +640,7 @@ cfg_parser_t* cfg_parser_init(str* filename)
640 640
 		goto error;
641 641
 	}
642 642
 
643
-	free(pathname);
643
+	pkg_free(pathname);
644 644
 
645 645
 	st->file = base;
646 646
 	st->line = 1;
... ...
@@ -653,7 +653,7 @@ cfg_parser_t* cfg_parser_init(str* filename)
653 653
 		pkg_free(st);
654 654
 	}
655 655
 	if (base) pkg_free(base);
656
-	if (pathname) free(pathname);
656
+	if (pathname) pkg_free(pathname);
657 657
 	return NULL;
658 658
 }
659 659
 
... ...
@@ -29,11 +29,10 @@
29 29
  */
30 30
 
31 31
 
32
-/*!
33
- * \file
34
- * \brief SIP-router core :: 
35
- * \ingroup core
36
- * Module: \ref core
32
+/** various utility functions.
33
+ * @file ut.c
34
+ * @ingroup core
35
+ * Module: @ref core
37 36
  */
38 37
 
39 38
 #include <sys/types.h>
... ...
@@ -215,6 +214,16 @@ unsigned int get_sys_version(int* major, int* minor, int* minor2)
215 215
 }
216 216
 
217 217
 
218
+
219
+/** transform a relative pathname into an absolute one.
220
+ * @param base  - base file, used to extract the absolute path prefix.
221
+ *                Might be NULL, in which case the path of the ser.cfg is
222
+ *                used.
223
+ * @param file  - file path to be transformed. If it's already absolute
224
+ *                (starts with '/') is left alone. If not the result will
225
+ *                be `dirname base`/file.
226
+ * @return  pkg allocated asciiz string or 0 on error.
227
+ */
218 228
 char* get_abs_pathname(str* base, str* file)
219 229
 {
220 230
 	str ser_cfg;
... ...
@@ -241,8 +250,8 @@ char* get_abs_pathname(str* base, str* file)
241 241
 	if (file->s[0] == '/') {
242 242
 		/* This is an absolute pathname, make a zero terminated
243 243
 		 * copy and use it as it is */
244
-		if ((res = malloc(file->len+1)) == NULL) {
245
-			ERR("get_abs_pathname: No memory left (malloc failed)\n");
244
+		if ((res = pkg_malloc(file->len+1)) == NULL) {
245
+			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
246 246
 		}
247 247
 		memcpy(res, file->s, file->len);
248 248
 		res[file->len]=0;
... ...
@@ -251,8 +260,8 @@ char* get_abs_pathname(str* base, str* file)
251 251
 		 * to the location of the base file
252 252
 		 */
253 253
 		/* Make a copy, function dirname may modify the string */
254
-		if ((buf = malloc(base->len+1)) == NULL) {
255
-			ERR("get_abs_pathname: No memory left (malloc failed)\n");
254
+		if ((buf = pkg_malloc(base->len+1)) == NULL) {
255
+			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
256 256
 			return NULL;
257 257
 		}
258 258
 		memcpy(buf, base->s, base->len);
... ...
@@ -260,16 +269,16 @@ char* get_abs_pathname(str* base, str* file)
260 260
 		dir = dirname(buf);
261 261
 		
262 262
 		len = strlen(dir);
263
-		if ((res = malloc(len + 1 + file->len + 1)) == NULL) {
264
-			ERR("get_abs_pathname: No memory left (malloc failed)\n");
265
-			free(buf);
263
+		if ((res = pkg_malloc(len + 1 + file->len + 1)) == NULL) {
264
+			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
265
+			pkg_free(buf);
266 266
 			return NULL;
267 267
 		}
268 268
 		memcpy(res, dir, len);
269 269
 		res[len] = '/';
270 270
 		memcpy(res + len + 1, file->s, file->len);
271 271
 		res[len + 1 + file->len] = '\0';
272
-		free(buf);
272
+		pkg_free(buf);
273 273
 	}
274 274
 	return res;
275 275
 }