Przeglądaj źródła

ctl: compile time option to use system memory allocator

- flag in module Makefile: -DCTL_SYSTEM_MALLOC
- turned on for the moment
Daniel-Constantin Mierla 13 lat temu
rodzic
commit
55a3671f99

+ 2 - 0
modules/ctl/Makefile

@@ -10,6 +10,8 @@ LIBS=
 MOD_INSTALL_UTILS=../../utils/sercmd
 MOD_INSTALL_UTILS=../../utils/sercmd
 # fifo support
 # fifo support
 DEFS+=-DUSE_FIFO
 DEFS+=-DUSE_FIFO
+# use system malloc
+DEFS+=-DCTL_SYSTEM_MALLOC
 
 
 DEFS+=-DSER_MOD_INTERFACE
 DEFS+=-DSER_MOD_INTERFACE
 
 

+ 22 - 21
modules/ctl/binrpc_run.c

@@ -37,6 +37,7 @@
 #include "../../mem/mem.h"
 #include "../../mem/mem.h"
 #include "../../clist.h"
 #include "../../clist.h"
 #include "io_listener.h"
 #include "io_listener.h"
+#include "ctl.h"
 
 
 #include <stdio.h>  /* vsnprintf */
 #include <stdio.h>  /* vsnprintf */
 #include <stdlib.h> /* strtod */
 #include <stdlib.h> /* strtod */
@@ -145,7 +146,7 @@ inline static int binrpc_gc_track(struct binrpc_ctx* ctx, void* p)
 	b=ctx->gc;
 	b=ctx->gc;
 	if (b==0 || (b->idx>=b->p_no)){
 	if (b==0 || (b->idx>=b->p_no)){
 		n=(b==0)?BINRPC_GC_IBSIZE:b->p_no*2;
 		n=(b==0)?BINRPC_GC_IBSIZE:b->p_no*2;
-		b=pkg_malloc(sizeof(*b)+n*sizeof(void*)-sizeof(b->p));
+		b=ctl_malloc(sizeof(*b)+n*sizeof(void*)-sizeof(b->p));
 		if (b==0)
 		if (b==0)
 			return -1;
 			return -1;
 		b->p_no=n;
 		b->p_no=n;
@@ -172,8 +173,8 @@ inline static void binrpc_gc_collect(struct binrpc_ctx* ctx)
 	for(b=ctx->gc; b; b=next){
 	for(b=ctx->gc; b; b=next){
 		next=b->next;
 		next=b->next;
 		for (i=0; i<b->idx; i++)
 		for (i=0; i<b->idx; i++)
-			pkg_free(b->p[i]);
-		pkg_free(b);
+			ctl_free(b->p[i]);
+		ctl_free(b);
 	}
 	}
 	ctx->gc=0;
 	ctx->gc=0;
 }
 }
@@ -184,7 +185,7 @@ static struct rpc_struct_l* new_rpc_struct()
 	struct rpc_struct_l* rs;
 	struct rpc_struct_l* rs;
 	
 	
 	/* alloc everything in one chunk */
 	/* alloc everything in one chunk */
-	rs=pkg_malloc(sizeof(struct rpc_struct_l)+STRUCT_MAX_BODY);
+	rs=ctl_malloc(sizeof(struct rpc_struct_l)+STRUCT_MAX_BODY);
 	if (rs==0)
 	if (rs==0)
 		goto error;
 		goto error;
 	memset(rs, 0, sizeof(struct rpc_struct_l));
 	memset(rs, 0, sizeof(struct rpc_struct_l));
@@ -192,7 +193,7 @@ static struct rpc_struct_l* new_rpc_struct()
 	if (binrpc_init_pkt(&rs->pkt,
 	if (binrpc_init_pkt(&rs->pkt,
 				(unsigned char*)rs+sizeof(struct rpc_struct_l),
 				(unsigned char*)rs+sizeof(struct rpc_struct_l),
 				STRUCT_MAX_BODY)<0){
 				STRUCT_MAX_BODY)<0){
-		pkg_free(rs);
+		ctl_free(rs);
 		goto error;
 		goto error;
 	}
 	}
 	return rs;
 	return rs;
@@ -212,7 +213,7 @@ static struct rpc_struct_l* grow_rpc_struct(struct rpc_struct_l *rs)
 	
 	
 	csize=binrpc_pkt_len(&rs->pkt);
 	csize=binrpc_pkt_len(&rs->pkt);
 	csize*=2;
 	csize*=2;
-	new_rs=pkg_realloc(rs, sizeof(struct rpc_struct_l)+csize);
+	new_rs=ctl_realloc(rs, sizeof(struct rpc_struct_l)+csize);
 	if (new_rs){
 	if (new_rs){
 		binrpc_pkt_update_buf(&rs->pkt, 
 		binrpc_pkt_update_buf(&rs->pkt, 
 							(unsigned char*)new_rs+sizeof(struct rpc_struct_l),
 							(unsigned char*)new_rs+sizeof(struct rpc_struct_l),
@@ -235,7 +236,7 @@ inline static int append_pkt_body(struct binrpc_pkt* p, unsigned char* buf,
 		size=2*(int)(p->end-p->body);
 		size=2*(int)(p->end-p->body);
 		offset=binrpc_pkt_len(p);
 		offset=binrpc_pkt_len(p);
 		for(;(size-offset)<len; size*=2); /* find new size */
 		for(;(size-offset)<len; size*=2); /* find new size */
-		new_b=pkg_realloc(p->body, size);
+		new_b=ctl_realloc(p->body, size);
 		if (new_b==0)
 		if (new_b==0)
 			goto error;
 			goto error;
 		binrpc_pkt_update_buf(p, new_b, size);
 		binrpc_pkt_update_buf(p, new_b, size);
@@ -339,7 +340,7 @@ static void free_structs(struct rpc_struct_head* sl_head)
 	clist_foreach_safe(sl_head, l, tmp, next){
 	clist_foreach_safe(sl_head, l, tmp, next){
 		free_structs(&l->substructs);
 		free_structs(&l->substructs);
 		memset(l, 0, sizeof(struct rpc_struct_l)); /* debugging */
 		memset(l, 0, sizeof(struct rpc_struct_l)); /* debugging */
-		pkg_free(l);
+		ctl_free(l);
 	};
 	};
 }
 }
 
 
@@ -370,7 +371,7 @@ inline static int init_binrpc_ctx(	struct binrpc_ctx* ctx,
 	
 	
 	/* alloc temporary body buffer */
 	/* alloc temporary body buffer */
 	send_buf_len=BINRPC_MAX_BODY;
 	send_buf_len=BINRPC_MAX_BODY;
-	send_buf=pkg_malloc(send_buf_len);
+	send_buf=ctl_malloc(send_buf_len);
 	if (send_buf==0){
 	if (send_buf==0){
 		err=E_BINRPC_LAST;
 		err=E_BINRPC_LAST;
 		goto end;
 		goto end;
@@ -387,11 +388,11 @@ inline void destroy_binrpc_ctx(struct binrpc_ctx* ctx)
 {
 {
 	free_structs(&ctx->out.structs);
 	free_structs(&ctx->out.structs);
 	if (ctx->out.pkt.body){
 	if (ctx->out.pkt.body){
-		pkg_free(ctx->out.pkt.body);
+		ctl_free(ctx->out.pkt.body);
 		ctx->out.pkt.body=0;
 		ctx->out.pkt.body=0;
 	}
 	}
 	if (ctx->err_phrase.s){
 	if (ctx->err_phrase.s){
-		pkg_free(ctx->err_phrase.s);
+		ctl_free(ctx->err_phrase.s);
 		ctx->err_phrase.s=NULL;
 		ctx->err_phrase.s=NULL;
 	}
 	}
 	binrpc_gc_collect(ctx);
 	binrpc_gc_collect(ctx);
@@ -512,8 +513,8 @@ static int rpc_fault_prepare(struct binrpc_ctx* ctx, int code, char* fmt, ...)
 
 
 	ctx->err_code = code;
 	ctx->err_code = code;
 	if (ctx->err_phrase.s)
 	if (ctx->err_phrase.s)
-		pkg_free(ctx->err_phrase.s);
-	ctx->err_phrase.s = (char*)pkg_malloc(sizeof(char)*len);
+		ctl_free(ctx->err_phrase.s);
+	ctx->err_phrase.s = (char*)ctl_malloc(sizeof(char)*len);
 	if (!ctx->err_phrase.s) {
 	if (!ctx->err_phrase.s) {
 		ctx->err_code = 0;
 		ctx->err_code = 0;
 		ctx->err_phrase.len = 0;
 		ctx->err_phrase.len = 0;
@@ -530,7 +531,7 @@ static void rpc_fault_reset(struct binrpc_ctx* ctx)
 {
 {
 	ctx->err_code = 0;
 	ctx->err_code = 0;
 	if (ctx->err_phrase.s) {
 	if (ctx->err_phrase.s) {
-		pkg_free(ctx->err_phrase.s);
+		ctl_free(ctx->err_phrase.s);
 		ctx->err_phrase.s = NULL;
 		ctx->err_phrase.s = NULL;
 		ctx->err_phrase.len = 0;
 		ctx->err_phrase.len = 0;
 	}
 	}
@@ -780,7 +781,7 @@ inline static str* binrpc_val_conv_str(struct binrpc_ctx* ctx,
 			return &v->u.strval;
 			return &v->u.strval;
 		case BINRPC_T_INT:
 		case BINRPC_T_INT:
 			s=int2str(v->u.intval, &len);
 			s=int2str(v->u.intval, &len);
-			ret=pkg_malloc(sizeof(*ret)+len+1);
+			ret=ctl_malloc(sizeof(*ret)+len+1);
 			if (ret==0 || binrpc_gc_track(ctx, ret)!=0){
 			if (ret==0 || binrpc_gc_track(ctx, ret)!=0){
 				*err=E_BINRPC_OVERFLOW;
 				*err=E_BINRPC_OVERFLOW;
 				return 0;
 				return 0;
@@ -1001,7 +1002,7 @@ static int rpc_printf(struct binrpc_ctx* ctx, char* fmt, ...)
 	int len;
 	int len;
 	int err;
 	int err;
 	
 	
-	buf=pkg_malloc(RPC_PRINTF_BUF_SIZE);
+	buf=ctl_malloc(RPC_PRINTF_BUF_SIZE);
 	if (buf==0) goto error;
 	if (buf==0) goto error;
 	va_start(ap, fmt);
 	va_start(ap, fmt);
 	len=vsnprintf(buf, RPC_PRINTF_BUF_SIZE, fmt, ap);
 	len=vsnprintf(buf, RPC_PRINTF_BUF_SIZE, fmt, ap);
@@ -1016,10 +1017,10 @@ static int rpc_printf(struct binrpc_ctx* ctx, char* fmt, ...)
 					" %s (%d)\n", binrpc_error(err), err);
 					" %s (%d)\n", binrpc_error(err), err);
 		goto error;
 		goto error;
 	}
 	}
-	pkg_free(buf);
+	ctl_free(buf);
 	return 0;
 	return 0;
 error:
 error:
-	if (buf) pkg_free(buf);
+	if (buf) ctl_free(buf);
 	return -1;
 	return -1;
 }
 }
 
 
@@ -1100,7 +1101,7 @@ static int rpc_struct_printf(struct rpc_struct_l *s, char* name,
 	int err;
 	int err;
 	struct binrpc_val avp;
 	struct binrpc_val avp;
 	
 	
-	buf=pkg_malloc(RPC_PRINTF_BUF_SIZE);
+	buf=ctl_malloc(RPC_PRINTF_BUF_SIZE);
 	if (buf==0) goto error;
 	if (buf==0) goto error;
 	va_start(ap, fmt);
 	va_start(ap, fmt);
 	len=vsnprintf(buf, RPC_PRINTF_BUF_SIZE, fmt, ap);
 	len=vsnprintf(buf, RPC_PRINTF_BUF_SIZE, fmt, ap);
@@ -1121,10 +1122,10 @@ static int rpc_struct_printf(struct rpc_struct_l *s, char* name,
 					" %s (%d)\n", binrpc_error(err), err);
 					" %s (%d)\n", binrpc_error(err), err);
 		goto error;
 		goto error;
 	}
 	}
-	pkg_free(buf);
+	ctl_free(buf);
 	return 0;
 	return 0;
 error:
 error:
-	if (buf) pkg_free(buf);
+	if (buf) ctl_free(buf);
 	return -1;
 	return -1;
 }
 }
 
 

+ 44 - 0
modules/ctl/ctl.h

@@ -0,0 +1,44 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2012 sip-router.org
+ *
+ * This file is part of ser, a free SIP server.
+ *
+ * ser is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * For a license to use the ser software under conditions
+ * other than those described here, or to purchase support for this
+ * software, please contact iptel.org by e-mail at the following addresses:
+ *    [email protected]
+ *
+ * ser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License 
+ * along with this program; if not, write to the Free Software 
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _CTL_MOD_H_
+#define _CTL_MOD_H_
+
+#ifdef CTL_SYSTEM_MALLOC
+#include <stdlib.h>
+#define ctl_malloc malloc
+#define ctl_realloc realloc
+#define ctl_free free
+#else
+#include "../../mem/mem.h"
+#define ctl_malloc pkg_malloc
+#define ctl_realloc pkg_realloc
+#define ctl_free pkg_free
+#endif
+
+#endif
+

+ 11 - 9
modules/ctl/ctrl_socks.c

@@ -39,8 +39,10 @@
 #include "fifo_server.h"
 #include "fifo_server.h"
 #endif
 #endif
 
 
+#include "ctl.h"
+
 /* parse proto:address:port   or proto:address */
 /* parse proto:address:port   or proto:address */
-/* returns struct id_list on success (pkg_malloc'ed), 0 on error
+/* returns struct id_list on success (ctl_malloc'ed), 0 on error
  * WARNING: it will add \0 in the string*/
  * WARNING: it will add \0 in the string*/
 /* parses:
 /* parses:
  *     tcp|udp|unix:host_name:port
  *     tcp|udp|unix:host_name:port
@@ -64,7 +66,7 @@ struct id_list* parse_listen_id(char* l, int len, enum socket_protos def)
 	char* s;
 	char* s;
 	struct id_list* id;
 	struct id_list* id;
 	
 	
-	s=pkg_malloc((len+1)*sizeof(char));
+	s=ctl_malloc((len+1)*sizeof(char));
 	if (s==0){
 	if (s==0){
 		LOG(L_ERR, "ERROR:parse_listen_id: out of memory\n");
 		LOG(L_ERR, "ERROR:parse_listen_id: out of memory\n");
 		goto error;
 		goto error;
@@ -192,7 +194,7 @@ end:
 			}
 			}
 		}
 		}
 	}
 	}
-	id=pkg_malloc(sizeof(struct id_list));
+	id=ctl_malloc(sizeof(struct id_list));
 	if (id==0){
 	if (id==0){
 		LOG(L_ERR, "ERROR:parse_listen_id: out of memory\n");
 		LOG(L_ERR, "ERROR:parse_listen_id: out of memory\n");
 		goto error;
 		goto error;
@@ -205,7 +207,7 @@ end:
 	id->next=0;
 	id->next=0;
 	return id;
 	return id;
 error:
 error:
-	if (s) pkg_free(s);
+	if (s) ctl_free(s);
 	return 0;
 	return 0;
 }
 }
 
 
@@ -213,7 +215,7 @@ error:
 void free_id_list_elem(struct id_list* id)
 void free_id_list_elem(struct id_list* id)
 {
 {
 	if (id->buf){
 	if (id->buf){
-		pkg_free(id->buf);
+		ctl_free(id->buf);
 		id->buf=0;
 		id->buf=0;
 	}
 	}
 }
 }
@@ -225,7 +227,7 @@ void free_id_list(struct id_list* l)
 	for (;l; l=nxt){
 	for (;l; l=nxt){
 		nxt=l->next;
 		nxt=l->next;
 		free_id_list_elem(l);
 		free_id_list_elem(l);
-		pkg_free(l);
+		ctl_free(l);
 	}
 	}
 }
 }
 
 
@@ -271,7 +273,7 @@ int init_ctrl_sockets(struct ctrl_socket** c_lst, struct id_list* lst,
 		}
 		}
 		if (s==-1) goto error;
 		if (s==-1) goto error;
 		/* add listener */
 		/* add listener */
-		cs=pkg_malloc(sizeof(struct ctrl_socket));
+		cs=ctl_malloc(sizeof(struct ctrl_socket));
 		if (cs==0){
 		if (cs==0){
 			LOG(L_ERR, "ERROR: init_ctrl_listeners: out of memory\n");
 			LOG(L_ERR, "ERROR: init_ctrl_listeners: out of memory\n");
 			goto error;
 			goto error;
@@ -302,7 +304,7 @@ void free_ctrl_socket_list(struct ctrl_socket* l)
 	for (;l; l=nxt){
 	for (;l; l=nxt){
 		nxt=l->next;
 		nxt=l->next;
 		if (l->data)
 		if (l->data)
-			pkg_free(l->data);
-		pkg_free(l);
+			ctl_free(l->data);
+		ctl_free(l);
 	}
 	}
 }
 }

+ 28 - 27
modules/ctl/fifo_server.c

@@ -55,7 +55,7 @@
  * History:
  * History:
  * --------
  * --------
  *  2003-03-29  destroy pkg mem introduced (jiri)
  *  2003-03-29  destroy pkg mem introduced (jiri)
- *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ *  2003-03-19  replaced all mallocs/frees w/ ctl_malloc/ctl_free (andrei)
  *  2003-01-29  new built-in fifo commands: arg and pwd (jiri)
  *  2003-01-29  new built-in fifo commands: arg and pwd (jiri)
  *  2003-10-07  fifo security fixes: permissions, always delete old fifo,
  *  2003-10-07  fifo security fixes: permissions, always delete old fifo,
  *               reply fifo checks -- added fifo_check (andrei)
  *               reply fifo checks -- added fifo_check (andrei)
@@ -101,6 +101,7 @@
 #include "../../tsend.h"
 #include "../../tsend.h"
 #include "fifo_server.h"
 #include "fifo_server.h"
 #include "io_listener.h"
 #include "io_listener.h"
+#include "ctl.h"
 
 
 
 
 #define MAX_FIFO_COMMAND        128    /* Maximum length of a FIFO server command */
 #define MAX_FIFO_COMMAND        128    /* Maximum length of a FIFO server command */
@@ -303,15 +304,15 @@ struct text_chunk* new_chunk_escape(str* src, int escape_all)
 	struct text_chunk* l;
 	struct text_chunk* l;
 	if (!src) return 0;
 	if (!src) return 0;
 
 
-        l = pkg_malloc(sizeof(struct text_chunk));
+        l = ctl_malloc(sizeof(struct text_chunk));
 	if (!l) {
 	if (!l) {
 		ERR("No Memory Left\n");
 		ERR("No Memory Left\n");
 		return 0;
 		return 0;
 	}
 	}
-	l->s.s = pkg_malloc(src->len * 2 + 1);
+	l->s.s = ctl_malloc(src->len * 2 + 1);
 	if (!l->s.s) {
 	if (!l->s.s) {
 		ERR("No Memory Left\n");
 		ERR("No Memory Left\n");
-		pkg_free(l);
+		ctl_free(l);
 		return 0;
 		return 0;
 	}
 	}
 	l->next = 0;
 	l->next = 0;
@@ -331,15 +332,15 @@ struct text_chunk* new_chunk(str* src)
 	struct text_chunk* l;
 	struct text_chunk* l;
 	if (!src) return 0;
 	if (!src) return 0;
 
 
-        l = pkg_malloc(sizeof(struct text_chunk));
+        l = ctl_malloc(sizeof(struct text_chunk));
 	if (!l) {
 	if (!l) {
 		ERR("No Memory Left\n");
 		ERR("No Memory Left\n");
 		return 0;
 		return 0;
 	}
 	}
-	l->s.s = pkg_malloc(src->len + 1);
+	l->s.s = ctl_malloc(src->len + 1);
 	if (!l->s.s) {
 	if (!l->s.s) {
 		ERR("No Memory Left\n");
 		ERR("No Memory Left\n");
-		pkg_free(l);
+		ctl_free(l);
 		return 0;
 		return 0;
 	}
 	}
 	l->next = 0;
 	l->next = 0;
@@ -360,22 +361,22 @@ struct text_chunk* new_chunk_unescape(str* src)
 	struct text_chunk* l;
 	struct text_chunk* l;
 	if (!src) return 0;
 	if (!src) return 0;
 
 
-        l = pkg_malloc(sizeof(struct text_chunk));
+        l = ctl_malloc(sizeof(struct text_chunk));
 	if (!l) {
 	if (!l) {
 		ERR("No Memory Left\n");
 		ERR("No Memory Left\n");
 		return 0;
 		return 0;
 	}
 	}
-	l->s.s = pkg_malloc(src->len + 1);
+	l->s.s = ctl_malloc(src->len + 1);
 	if (!l->s.s) {
 	if (!l->s.s) {
 		ERR("No Memory Left\n");
 		ERR("No Memory Left\n");
-		pkg_free(l);
+		ctl_free(l);
 		return 0;
 		return 0;
 	}
 	}
 	l->next = 0;
 	l->next = 0;
 	l->flags = 0;
 	l->flags = 0;
 	if (unescape(&l->s, src->s, src->len) < 0) {
 	if (unescape(&l->s, src->s, src->len) < 0) {
-		pkg_free(l->s.s);
-		pkg_free(l);
+		ctl_free(l->s.s);
+		ctl_free(l);
 		return 0;
 		return 0;
 	}
 	}
 	l->s.s[l->s.len] = '\0';
 	l->s.s[l->s.len] = '\0';
@@ -385,8 +386,8 @@ struct text_chunk* new_chunk_unescape(str* src)
 
 
 static void free_chunk(struct text_chunk* c)
 static void free_chunk(struct text_chunk* c)
 {
 {
-	if (c && c->s.s) pkg_free(c->s.s);
-	if (c) pkg_free(c);
+	if (c && c->s.s) ctl_free(c->s.s);
+	if (c) ctl_free(c);
 }
 }
 
 
 
 
@@ -407,7 +408,7 @@ static void free_struct(struct rpc_struct* s)
 		free_chunk(c);
 		free_chunk(c);
 	}
 	}
 
 
-	pkg_free(s);
+	ctl_free(s);
 }
 }
 
 
 
 
@@ -427,7 +428,7 @@ static struct rpc_struct* new_struct(rpc_ctx_t* ctx, str* line)
 		return 0;
 		return 0;
 	}
 	}
 
 
-	s = (struct rpc_struct*)pkg_malloc(sizeof(struct rpc_struct));
+	s = (struct rpc_struct*)ctl_malloc(sizeof(struct rpc_struct));
 	if (!s) {
 	if (!s) {
 		rpc_fault(ctx, 500, "Internal Server Error (No Memory Left)");
 		rpc_fault(ctx, 500, "Internal Server Error (No Memory Left)");
 		return 0;
 		return 0;
@@ -520,8 +521,8 @@ static int read_line(char** b, int* read, struct readline_handle* rh)
  * Remove directory path from filename and replace it
  * Remove directory path from filename and replace it
  * with the path configured through a module parameter.
  * with the path configured through a module parameter.
  * 
  * 
- * The result is allocated using pkg_malloc and thus
- * has to be freed using pkg_free
+ * The result is allocated using ctl_malloc and thus
+ * has to be freed using ctl_free
  */
  */
 static char *trim_filename(char * file)
 static char *trim_filename(char * file)
 {
 {
@@ -538,7 +539,7 @@ static char *trim_filename(char * file)
 		return 0;
 		return 0;
 	}
 	}
 	prefix_len = strlen(fifo_dir); fn_len = strlen(file);
 	prefix_len = strlen(fifo_dir); fn_len = strlen(file);
-	new_fn = pkg_malloc(prefix_len + fn_len + 1);
+	new_fn = ctl_malloc(prefix_len + fn_len + 1);
 	if (new_fn == 0) {
 	if (new_fn == 0) {
 		ERR("No memory left\n");
 		ERR("No memory left\n");
 		return 0;
 		return 0;
@@ -787,7 +788,7 @@ process:
 		}
 		}
 
 
 		if (context.reply_file) { 
 		if (context.reply_file) { 
-			pkg_free(context.reply_file); 
+			ctl_free(context.reply_file); 
 			context.reply_file = 0; 
 			context.reply_file = 0; 
 		}
 		}
 		
 		
@@ -1218,7 +1219,7 @@ static int rpc_struct_printf(struct text_chunk* c, char* name, char* fmt, ...)
 	rpc_ctx_t* ctx;
 	rpc_ctx_t* ctx;
 	
 	
 	ctx=(rpc_ctx_t*)c->ctx;
 	ctx=(rpc_ctx_t*)c->ctx;
-	buf = (char*)pkg_malloc(RPC_BUF_SIZE);
+	buf = (char*)ctl_malloc(RPC_BUF_SIZE);
 	if (!buf) {
 	if (!buf) {
 		rpc_fault(ctx,  500, "Internal Server Error (No memory left)");
 		rpc_fault(ctx,  500, "Internal Server Error (No memory left)");
 		ERR("No memory left\n");
 		ERR("No memory left\n");
@@ -1268,7 +1269,7 @@ static int rpc_struct_printf(struct text_chunk* c, char* name, char* fmt, ...)
 		} else {          /* glibc 2.0 */
 		} else {          /* glibc 2.0 */
 			buf_size *= 2;  /* twice the old size */
 			buf_size *= 2;  /* twice the old size */
 		}
 		}
-		if ((buf = pkg_realloc(buf, buf_size)) == 0) {
+		if ((buf = ctl_realloc(buf, buf_size)) == 0) {
 			rpc_fault(ctx, 500, "Internal Server Error (No memory left)");
 			rpc_fault(ctx, 500, "Internal Server Error (No memory left)");
 			ERR("No memory left\n");
 			ERR("No memory left\n");
 			goto err;
 			goto err;
@@ -1276,7 +1277,7 @@ static int rpc_struct_printf(struct text_chunk* c, char* name, char* fmt, ...)
 	}
 	}
 	return 0;
 	return 0;
  err:
  err:
-	if (buf) pkg_free(buf);
+	if (buf) ctl_free(buf);
 	return -1;
 	return -1;
 }
 }
 
 
@@ -1289,7 +1290,7 @@ static int rpc_printf(rpc_ctx_t* ctx, char* fmt, ...)
 	str s;
 	str s;
 	struct text_chunk* l;
 	struct text_chunk* l;
 
 
-	buf = (char*)pkg_malloc(RPC_BUF_SIZE);
+	buf = (char*)ctl_malloc(RPC_BUF_SIZE);
 	if (!buf) {
 	if (!buf) {
 		rpc_fault(ctx,  500, "Internal Server Error (No memory left)");
 		rpc_fault(ctx,  500, "Internal Server Error (No memory left)");
 		ERR("No memory left\n");
 		ERR("No memory left\n");
@@ -1313,7 +1314,7 @@ static int rpc_printf(rpc_ctx_t* ctx, char* fmt, ...)
 				goto err;
 				goto err;
 			}
 			}
 			append_chunk(ctx, l);
 			append_chunk(ctx, l);
-			pkg_free(buf);
+			ctl_free(buf);
 			return 0;
 			return 0;
 		}
 		}
 		     /* Else try again with more space. */
 		     /* Else try again with more space. */
@@ -1322,7 +1323,7 @@ static int rpc_printf(rpc_ctx_t* ctx, char* fmt, ...)
 		} else {          /* glibc 2.0 */
 		} else {          /* glibc 2.0 */
 			buf_size *= 2;  /* twice the old size */
 			buf_size *= 2;  /* twice the old size */
 		}
 		}
-		if ((buf = pkg_realloc(buf, buf_size)) == 0) {
+		if ((buf = ctl_realloc(buf, buf_size)) == 0) {
 			rpc_fault(ctx, 500, "Internal Server Error (No memory left)");
 			rpc_fault(ctx, 500, "Internal Server Error (No memory left)");
 			ERR("No memory left\n");
 			ERR("No memory left\n");
 			goto err;
 			goto err;
@@ -1330,7 +1331,7 @@ static int rpc_printf(rpc_ctx_t* ctx, char* fmt, ...)
 	}
 	}
 	return 0;
 	return 0;
  err:
  err:
-	if (buf) pkg_free(buf);
+	if (buf) ctl_free(buf);
 	return -1;
 	return -1;
 }
 }
 
 

+ 3 - 2
modules/ctl/io_listener.c

@@ -46,6 +46,7 @@
 #endif
 #endif
 
 
 #include "io_listener.h"
 #include "io_listener.h"
+#include "ctl.h"
 
 
 #define HANDLE_IO_INLINE
 #define HANDLE_IO_INLINE
 #include "../../io_wait.h"
 #include "../../io_wait.h"
@@ -106,7 +107,7 @@ static struct stream_connection* s_conn_new(int sock,
 {
 {
 	struct stream_connection* s_c;
 	struct stream_connection* s_c;
 	
 	
-	s_c=pkg_malloc(sizeof(struct stream_connection));
+	s_c=ctl_malloc(sizeof(struct stream_connection));
 	if (s_c){
 	if (s_c){
 		memset(s_c, 0, sizeof(struct stream_connection));
 		memset(s_c, 0, sizeof(struct stream_connection));
 		s_c->fd=sock;
 		s_c->fd=sock;
@@ -129,7 +130,7 @@ static struct stream_connection* s_conn_new(int sock,
 inline static void s_conn_rm(struct stream_connection* sc)
 inline static void s_conn_rm(struct stream_connection* sc)
 {
 {
 	clist_rm(sc, next, prev);
 	clist_rm(sc, next, prev);
-	pkg_free(sc);
+	ctl_free(sc);
 	io_read_connections--;
 	io_read_connections--;
 }
 }