[PATCH 4/4] core:proxy.c Proxy takes ownership of its name
Marius Zbihlei
marius.zbihlei at 1and1.ro
Wed Jan 27 11:39:37 CET 2010
Because the proxy only kept a pointer to the given name, that value can change depending of context.
In case of add_proxy()/find_proxy() calls this causes incorrect values to be returned.
---
proxy.c | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/proxy.c b/proxy.c
index a9c39b7..83f4285 100644
--- a/proxy.c
+++ b/proxy.c
@@ -245,7 +245,15 @@ error:
goto error; \
} \
memset(p,0,sizeof(struct proxy_l)); \
- p->name=*name; \
+ p->name.s = (char*)p_malloc(sizeof(char)*name->len); \
+ if (p->name.s==0){ \
+ ser_error=E_OUT_OF_MEM; \
+ ERR("ERROR: mk_proxy: memory allocation failure\n"); \
+ p_free(p); \
+ goto error; \
+ } \
+ p->name.len = name->len ; \
+ memcpy(p->name.s, name->s, name->len); \
p->port=port; \
\
DBG("DEBUG: mk_proxy: doing DNS lookup...\n"); \
@@ -255,10 +263,12 @@ error:
ser_error=E_BAD_ADDRESS; \
LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:" \
" \"%.*s\"\n", name->len, name->s); \
+ p_free(p->name.s); \
p_free(p); \
goto error; \
} \
if (he_cpy(&(p->host), he)!=0){ \
+ p_free(p->name.s); \
p_free(p); \
goto error; \
} \
@@ -322,15 +332,19 @@ error:
}
-
-
void free_proxy(struct proxy_l* p)
{
- if (p) free_hostent(&p->host);
+ if (p){
+ pkg_free(p->name.s);
+ free_hostent(&p->host);
+ }
}
void free_shm_proxy(struct proxy_l* p)
{
- if (p) free_shm_hostent(&p->host);
+ if (p){
+ shm_free(p->name.s);
+ free_shm_hostent(&p->host);
+ }
}
--
1.6.4.3
--------------000501090701080703090905--
More information about the sr-dev
mailing list