]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Move all pair* to talloc
authorAlan T. DeKok <aland@freeradius.org>
Mon, 18 Feb 2013 21:48:36 +0000 (16:48 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 19 Feb 2013 21:13:38 +0000 (16:13 -0500)
src/include/radiusd.h
src/lib/valuepair.c
src/main/evaluate.c
src/main/util.c
src/main/valuepair.c

index 9513591e45d699ce47eb9d917de9011307cdddd6..13e43e9f2b7cc10178ca1560455914be4ae8de49 100644 (file)
@@ -570,6 +570,7 @@ int         rad_mkdir(char *directory, mode_t mode);
 int            rad_checkfilename(const char *filename);
 void           *rad_malloc(size_t size); /* calls exit(1) on error! */
 void           *rad_calloc(size_t size); /* calls exit(1) on error! */
+void           rad_const_free(const void *ptr);
 void           rad_cfree(const void *ptr);
 REQUEST                *request_alloc(void);
 REQUEST                *request_alloc_fake(REQUEST *oldreq);
index 24ddfaad2316d59ff92ce09c78ffeab6011cb73a..214369b63ff490e0cae6815281c90d9115bc1d1c 100644 (file)
@@ -27,10 +27,6 @@ RCSID("$Id$")
 
 #include       <ctype.h>
 
-#ifdef HAVE_MALLOC_H
-#  include     <malloc.h>
-#endif
-
 #ifdef HAVE_PCREPOSIX_H
 #define WITH_REGEX
 #  include     <pcreposix.h>
@@ -111,10 +107,6 @@ VALUE_PAIR *paircreate(unsigned int attr, unsigned int vendor)
  */
 void pairbasicfree(VALUE_PAIR *pair)
 {
-       if (pair->da->type == PW_TYPE_TLV) {
-               free(pair->vp_tlv);
-       }
-       
        /*
         *      Only free the DICT_ATTR if it was dynamically allocated
         *      and was marked for free when the VALUE_PAIR is freed.
@@ -123,19 +115,6 @@ void pairbasicfree(VALUE_PAIR *pair)
                dict_attr_free(&(pair->da));
        }
        
-       switch (pair->type)
-       {
-       case VT_XLAT:
-               {
-                       char *tmp;
-               
-                       memcpy(&tmp, &pair->value.xlat, sizeof(tmp));
-                       free(tmp);
-               }
-       default:
-               break;
-       }
-       
        /* clear the memory here */
        memset(pair, 0, sizeof(*pair));
        talloc_free(pair);
@@ -330,7 +309,7 @@ VALUE_PAIR *paircopyvp(const VALUE_PAIR *vp)
 
        if (!vp) return NULL;
        
-       n = malloc(sizeof(*n));
+       n = pairalloc(NULL, vp->da);
        if (!n) {
                fr_strerror_printf("out of memory");
                return NULL;
@@ -343,7 +322,7 @@ VALUE_PAIR *paircopyvp(const VALUE_PAIR *vp)
         *      Now copy the value
         */
        if (vp->type == VT_XLAT) {
-               n->value.xlat = strdup(n->value.xlat);
+               n->value.xlat = talloc_strdup(n, n->value.xlat);
        }
        
        n->da = dict_attr_copy(vp->da, TRUE);
@@ -357,7 +336,7 @@ VALUE_PAIR *paircopyvp(const VALUE_PAIR *vp)
 
        if ((n->da->type == PW_TYPE_TLV) &&
            (n->vp_tlv != NULL)) {
-               n->vp_tlv = malloc(n->length);
+               n->vp_tlv = talloc_size(n, n->length);
                memcpy(n->vp_tlv, vp->vp_tlv, n->length);
        }
 
@@ -392,12 +371,12 @@ VALUE_PAIR *paircopyvpdata(const DICT_ATTR *da, const VALUE_PAIR *vp)
        n->da = da;
 
        if (n->type == VT_XLAT) {
-               n->value.xlat = strdup(n->value.xlat);
+               n->value.xlat = talloc_strdup(n, n->value.xlat);
        }
        
        if ((n->da->type == PW_TYPE_TLV) &&
            (n->vp_tlv != NULL)) {
-               n->vp_tlv = malloc(n->length);
+               n->vp_tlv = talloc_size(n, n->length);
                memcpy(n->vp_tlv, vp->vp_tlv, n->length);
        }
        
@@ -942,7 +921,7 @@ static int check_for_whitespace(const char *value)
 
 int pairparsevalue(VALUE_PAIR *vp, const char *value)
 {
-       char            *p, *s=0;
+       char            *p;
        const char      *cp, *cs;
        int             x;
        unsigned long long y;
@@ -1038,7 +1017,6 @@ int pairparsevalue(VALUE_PAIR *vp, const char *value)
                 *      FIXME: complain if hostname
                 *      cannot be resolved, or resolve later!
                 */
-               s = NULL;
                p = NULL;
                cs = value;
 
@@ -1047,13 +1025,11 @@ int pairparsevalue(VALUE_PAIR *vp, const char *value)
 
                        if (ip_hton(cs, AF_INET, &ipaddr) < 0) {
                                fr_strerror_printf("Failed to find IP address for %s", cs);
-                               free(s);
                                return FALSE;
                        }
 
                        vp->vp_ipaddr = ipaddr.ipaddr.ip4addr.s_addr;
                }
-               free(s);
                vp->length = 4;
                break;
 
@@ -1201,7 +1177,7 @@ int pairparsevalue(VALUE_PAIR *vp, const char *value)
 
                        vp->length = size >> 1;
                        if (size > 2*sizeof(vp->vp_octets)) {
-                               us = vp->vp_tlv = malloc(vp->length);
+                               us = vp->vp_tlv = talloc_size(vp, vp->length);
                                if (!us) {
                                        fr_strerror_printf("Out of memory.");
                                        return FALSE;
@@ -1406,10 +1382,9 @@ int pairparsevalue(VALUE_PAIR *vp, const char *value)
                }
                length = strlen(value + 2) / 2;
                if (vp->length < length) {
-                       free(vp->vp_tlv);
-                       vp->vp_tlv = NULL;
+                       TALLOC_FREE(vp->vp_tlv);
                }
-               vp->vp_tlv = malloc(length);
+               vp->vp_tlv = talloc_size(vp, length);
                if (!vp->vp_tlv) {
                        fr_strerror_printf("No memory");
                        return FALSE;
@@ -1488,10 +1463,10 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value,
 
        vp->length = size >> 1;
        if (vp->length > sizeof(vp->vp_octets)) {
-               vp->vp_tlv = malloc(vp->length);
+               vp->vp_tlv = talloc_size(vp, vp->length);
                if (!vp->vp_tlv) {
                        fr_strerror_printf("Out of memory");
-                       free(vp);
+                       talloc_free(vp);
                        return NULL;
                }
                data = vp->vp_tlv;
@@ -1499,7 +1474,7 @@ static VALUE_PAIR *pairmake_any(const char *attribute, const char *value,
 
        if (fr_hex2bin(value + 2, data, size) != vp->length) {
                fr_strerror_printf("Invalid hex string");
-               free(vp);
+               talloc_free(vp);
                return NULL;
        }
 
@@ -1738,7 +1713,7 @@ int pairmark_xlat(VALUE_PAIR *vp, const char *value)
                return -1;
        }
        
-       raw = strdup(value);
+       raw = talloc_strdup(vp, value);
        if (!raw) {
                return -1;
        }
index 91c0bd8bf71aac79bde678e4fbcbdf3c26979ff8..fa2fa3f4884b481829b0d9f9a4de3a7a7fec8b24 100644 (file)
@@ -1207,9 +1207,15 @@ int radius_update_attrlist(REQUEST *request, CONF_SECTION *cs,
                 *      not, panic.
                 */
                if (vp->type == VT_XLAT) {
+                       char *tmp;
                        const char *value;
                        char buffer[2048];
 
+                       rad_const_free(vp->value.xlat);
+                       vp->value.xlat = NULL;
+
+                       vp->type = VT_DATA;
+
                        value = expand_string(buffer, sizeof(buffer), request,
                                              cp->value_type, cp->value);
                        if (!value) {
@@ -1223,11 +1229,6 @@ int radius_update_attrlist(REQUEST *request, CONF_SECTION *cs,
                                pairfree(&newlist);
                                return RLM_MODULE_FAIL;
                        }
-                       
-                       rad_cfree(vp->value.xlat);
-                       vp->value.xlat = NULL;
-                       
-                       vp->type = VT_DATA;
                }
                vp = vp->next;
        }
index 7ad7163d04d3ea4dc3c602816c24db8cadd3b37b..c66b6efb55ae32a46e1416dc97263c05d95fb1fc 100644 (file)
@@ -376,6 +376,16 @@ void *rad_calloc(size_t size)
        return ptr;
 }
 
+void rad_const_free(const void *ptr)
+{
+       void *tmp;
+       if (!ptr) return;
+
+       memcpy(&tmp, &ptr, sizeof(tmp));
+       talloc_free(tmp);
+}
+
+
 /*
  *     Signature for free is dumb, and raises errors when we try
  *     to free const ptrs.
index b0f662dc267e0d960dc1315601275ea181471caa..a66033ea1ca51cf48987fb32cb6610eae8336717 100644 (file)
@@ -659,9 +659,8 @@ int radius_xlat_do(REQUEST *request, VALUE_PAIR *vp)
        len = radius_xlat(buffer, sizeof(buffer), vp->value.xlat, request,
                          NULL, NULL);
 
-       rad_cfree(vp->value.xlat);
+       rad_const_free(vp->value.xlat);
        vp->value.xlat = NULL;
-       
        if (!len) {
                return -1;
        }