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 214
 }
216 215
 
217 216
 
217
+
218
+/** transform a relative pathname into an absolute one.
219
+ * @param base  - base file, used to extract the absolute path prefix.
220
+ *                Might be NULL, in which case the path of the ser.cfg is
221
+ *                used.
222
+ * @param file  - file path to be transformed. If it's already absolute
223
+ *                (starts with '/') is left alone. If not the result will
224
+ *                be `dirname base`/file.
225
+ * @return  pkg allocated asciiz string or 0 on error.
226
+ */
218 227
 char* get_abs_pathname(str* base, str* file)
219 228
 {
220 229
 	str ser_cfg;
... ...
@@ -241,8 +250,8 @@ char* get_abs_pathname(str* base, str* file)
241 250
 	if (file->s[0] == '/') {
242 251
 		/* This is an absolute pathname, make a zero terminated
243 252
 		 * 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");
253
+		if ((res = pkg_malloc(file->len+1)) == NULL) {
254
+			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
246 255
 		}
247 256
 		memcpy(res, file->s, file->len);
248 257
 		res[file->len]=0;
... ...
@@ -251,8 +260,8 @@ char* get_abs_pathname(str* base, str* file)
251 260
 		 * to the location of the base file
252 261
 		 */
253 262
 		/* 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");
263
+		if ((buf = pkg_malloc(base->len+1)) == NULL) {
264
+			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
256 265
 			return NULL;
257 266
 		}
258 267
 		memcpy(buf, base->s, base->len);
... ...
@@ -260,16 +269,16 @@ char* get_abs_pathname(str* base, str* file)
260 269
 		dir = dirname(buf);
261 270
 		
262 271
 		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);
272
+		if ((res = pkg_malloc(len + 1 + file->len + 1)) == NULL) {
273
+			ERR("get_abs_pathname: No memory left (pkg_malloc failed)\n");
274
+			pkg_free(buf);
266 275
 			return NULL;
267 276
 		}
268 277
 		memcpy(res, dir, len);
269 278
 		res[len] = '/';
270 279
 		memcpy(res + len + 1, file->s, file->len);
271 280
 		res[len + 1 + file->len] = '\0';
272
-		free(buf);
281
+		pkg_free(buf);
273 282
 	}
274 283
 	return res;
275 284
 }