#include <ctype.h>
-#ifdef HAVE_MALLOC_H
-# include <malloc.h>
-#endif
-
#ifdef HAVE_PCREPOSIX_H
#define WITH_REGEX
# include <pcreposix.h>
*/
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.
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);
if (!vp) return NULL;
- n = malloc(sizeof(*n));
+ n = pairalloc(NULL, vp->da);
if (!n) {
fr_strerror_printf("out of memory");
return NULL;
* 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);
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);
}
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);
}
int pairparsevalue(VALUE_PAIR *vp, const char *value)
{
- char *p, *s=0;
+ char *p;
const char *cp, *cs;
int x;
unsigned long long y;
* FIXME: complain if hostname
* cannot be resolved, or resolve later!
*/
- s = NULL;
p = NULL;
cs = 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;
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;
}
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;
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;
if (fr_hex2bin(value + 2, data, size) != vp->length) {
fr_strerror_printf("Invalid hex string");
- free(vp);
+ talloc_free(vp);
return NULL;
}
return -1;
}
- raw = strdup(value);
+ raw = talloc_strdup(vp, value);
if (!raw) {
return -1;
}