}
#endif
- free(client->longname);
- free(client->secret);
- free(client->shortname);
- free(client->nastype);
- free(client->login);
- free(client->password);
- free(client->server);
-
-#ifdef WITH_DYNAMIC_CLIENTS
- free(client->client_server);
-#endif
-
- free(client);
+ talloc_free(client);
}
/*
*/
#endif
- free(clients);
+ talloc_free(clients);
}
/*
*/
RADCLIENT_LIST *clients_init(void)
{
- RADCLIENT_LIST *clients = calloc(1, sizeof(RADCLIENT_LIST));
+ RADCLIENT_LIST *clients = talloc_zero(NULL, RADCLIENT_LIST);
if (!clients) return NULL;
/*
* The size is fine.. Let's create the buffer
*/
- c = rad_malloc(sizeof(*c));
- memset(c, 0, sizeof(*c));
+ c = talloc_zero(cs, RADCLIENT);
c->cs = cs;
memset(&cl_ip4addr, 0, sizeof(cl_ip4addr));
error:
client_free(c);
#ifdef WITH_TCP
- free(hs_proto);
hs_proto = NULL;
- free(cl_srcipaddr);
cl_srcipaddr = NULL;
#endif
#ifdef WITH_TCP
if (hs_proto) {
if (strcmp(hs_proto, "udp") == 0) {
- free(hs_proto);
hs_proto = NULL;
} else if (strcmp(hs_proto, "tcp") == 0) {
- free(hs_proto);
hs_proto = NULL;
c->proto = IPPROTO_TCP;
} else if (strcmp(hs_proto, "*") == 0) {
- free(hs_proto);
hs_proto = NULL;
c->proto = IPPROTO_IP; /* fake for dual */
DEBUGW("Server not build with udpfromto, ignoring client src_ipaddr");
#endif
- free(cl_srcipaddr);
cl_srcipaddr = NULL;
}
if (strcmp("server", cf_section_name1(section)) == 0) in_server = TRUE;
- /*
- * Associate the clients structure with the section, where
- * it will be freed once the section is freed.
- */
- if (cf_data_add(section, "clients", clients, (void *) clients_free) < 0) {
- cf_log_err(cf_sectiontoitem(section),
- "Failed to associate clients with section %s",
- cf_section_name1(section));
- clients_free(clients);
- return NULL;
- }
-
for (cs = cf_subsection_find_next(section, NULL, "client");
cs != NULL;
cs = cf_subsection_find_next(section, cs, "client")) {
if (!clients || !request) return NULL;
- c = rad_malloc(sizeof(*c));
- memset(c, 0, sizeof(*c));
+ c = talloc_zero(clients, RADCLIENT);
c->cs = request->client->cs;
c->ipaddr.af = AF_UNSPEC;
c->src_ipaddr.af = AF_UNSPEC;
case PW_TYPE_STRING_PTR:
p = (char **) ((char *) c + dynamic_config[i].offset);
- if (*p) free(*p);
+ if (*p) talloc_free(*p);
if (vp->vp_strvalue[0]) {
- *p = strdup(vp->vp_strvalue);
+ *p = talloc_strdup(c->cs, vp->vp_strvalue);
} else {
*p = NULL;
}
return (CONF_ITEM *)cs;
}
-static CONF_DATA *cf_itemtodata(CONF_ITEM *ci)
-{
- if (ci == NULL)
- return NULL;
- rad_assert(ci->type == CONF_ITEM_DATA);
- return (CONF_DATA *)ci;
-}
static CONF_ITEM *cf_datatoitem(CONF_DATA *cd)
{
if (cd == NULL)
FR_TOKEN op, FR_TOKEN value_type,
CONF_SECTION *parent)
{
- char *p;
- size_t attr_len, value_len = 0;
CONF_PAIR *cp;
if (!attr) return NULL;
- attr_len = strlen(attr) + 1;
- if (value) value_len = strlen(value) + 1;
- p = rad_malloc(sizeof(*cp) + attr_len + value_len);
+ cp = talloc_zero(parent, CONF_PAIR);
+ if (!cp) return NULL;
- cp = (CONF_PAIR *) p;
- memset(cp, 0, sizeof(*cp));
cp->item.type = CONF_ITEM_PAIR;
cp->item.parent = parent;
+ cp->value_type = value_type;
+ cp->op = op;
- p += sizeof(*cp);
- memcpy(p, attr, attr_len);
- cp->attr = p;
+ cp->attr = talloc_strdup(cp, attr);
+ if (!cp->attr) {
+ error:
+ talloc_free(cp);
+ return NULL;
+ }
if (value) {
- p += attr_len;
- memcpy(p, value, value_len);
- cp->value = p;
+ cp->value = talloc_strdup(cp, value);
+ if (!cp->value) goto error;
}
- cp->value_type = value_type;
- cp->op = op;
return cp;
}
-/*
- * Free a CONF_PAIR
- */
-void cf_pair_free(CONF_PAIR **cp)
+static int cf_data_free(void *ctx)
{
- if (!cp || !*cp) return;
-
- /*
- * attr && value are allocated contiguous with cp.
- */
+ CONF_DATA *cd;
-#ifndef NDEBUG
- memset(*cp, 0, sizeof(cp));
-#endif
- free(*cp);
+ cd = talloc_get_type_abort(ctx, CONF_DATA);
+ cd->free(cd->data);
- *cp = NULL;
+ return 0;
}
-static void cf_data_free(CONF_DATA **cd)
-{
- if (!cd || !*cd) return;
-
- /* name is allocated contiguous with cd */
- if (!(*cd)->free) {
- free((*cd)->data);
- } else {
- ((*cd)->free)((*cd)->data);
- }
-#ifndef NDEBUG
- memset(*cd, 0, sizeof(cd));
-#endif
- free(*cd);
- *cd = NULL;
-}
/*
* rbtree callback function
return strcmp(one->name, two->name);
}
-
-/*
- * Free strings we've parsed into data structures.
- */
-void cf_section_parse_free(CONF_SECTION *cs, void *base)
-{
- int i;
- const CONF_PARSER *variables = cs->variables;
-
- /*
- * Don't automatically free the strings if we're being
- * called from a module. This is also for clients.c,
- * where client_free() expects to be able to free the
- * client structure. If we moved everything to key off
- * of the config files, we might solve some problems...
- */
- if (!variables) return;
-
- /*
- * Free up dynamically allocated string pointers.
- */
- for (i = 0; variables[i].name != NULL; i++) {
- int type;
- char **p;
-
- type = variables[i].type & ~PW_TYPE_DEPRECATED;
-
- if (type == PW_TYPE_SUBSECTION) {
- CONF_SECTION *subcs;
- subcs = cf_section_sub_find(cs, variables[i].name);
-
- if (!subcs) continue;
-
- if (!variables[i].dflt) continue;
-
- cf_section_parse_free(subcs, base);
- continue;
- }
-
- if ((type != PW_TYPE_STRING_PTR) &&
- (type != PW_TYPE_FILENAME)) {
- continue;
- }
-
- /*
- * No base struct offset, data must be the pointer.
- * If data doesn't exist, ignore the entry, there
- * must be something wrong.
- */
- if (!base) {
- if (!variables[i].data) {
- continue;
- }
-
- p = (char **) variables[i].data;;
-
- } else if (variables[i].data) {
- p = (char **) variables[i].data;;
-
- } else {
- p = (char **) (((char *)base) + variables[i].offset);
- }
-
- free(*p);
- *p = NULL;
- }
-
- cs->variables = NULL;
-}
-
-
-/*
- * Free a CONF_SECTION
- */
-void cf_section_free(CONF_SECTION **cs)
+static int cf_section_free(void *ctx)
{
- CONF_ITEM *ci, *next;
-
- if (!cs || !*cs) return;
-
- cf_section_parse_free(*cs, (*cs)->base);
-
- for (ci = (*cs)->children; ci; ci = next) {
- next = ci->next;
-
- switch (ci->type) {
- case CONF_ITEM_PAIR: {
- CONF_PAIR *pair = cf_itemtopair(ci);
- cf_pair_free(&pair);
- }
- break;
-
- case CONF_ITEM_SECTION: {
- CONF_SECTION *section = cf_itemtosection(ci);
- cf_section_free(§ion);
- }
- break;
-
- case CONF_ITEM_DATA: {
- CONF_DATA *data = cf_itemtodata(ci);
- cf_data_free(&data);
- }
- break;
+ CONF_SECTION *cs;
- default: /* should really be an error. */
- break;
- }
- }
- (*cs)->children = NULL;
+ cs = talloc_get_type_abort(ctx, CONF_SECTION);
/*
* Name1 and name2 are allocated contiguous with
* cs.
*/
- if ((*cs)->pair_tree) {
- rbtree_free((*cs)->pair_tree);
- (*cs)->pair_tree = NULL;
+ if (cs->pair_tree) {
+ rbtree_free(cs->pair_tree);
+ cs->pair_tree = NULL;
}
- if ((*cs)->section_tree) {
- rbtree_free((*cs)->section_tree);
- (*cs)->section_tree = NULL;
+ if (cs->section_tree) {
+ rbtree_free(cs->section_tree);
+ cs->section_tree = NULL;
}
- if ((*cs)->name2_tree) {
- rbtree_free((*cs)->name2_tree);
- (*cs)->name2_tree = NULL;
+ if (cs->name2_tree) {
+ rbtree_free(cs->name2_tree);
+ cs->name2_tree = NULL;
}
- if ((*cs)->data_tree) {
- rbtree_free((*cs)->data_tree);
- (*cs)->data_tree = NULL;
+ if (cs->data_tree) {
+ rbtree_free(cs->data_tree);
+ cs->data_tree = NULL;
}
- /*
- * And free the section
- */
-#ifndef NDEBUG
- memset(*cs, 0, sizeof(cs));
-#endif
- free(*cs);
-
- *cs = NULL;
+ return 0;
}
static CONF_SECTION *cf_section_alloc(const char *name1, const char *name2,
CONF_SECTION *parent)
{
- size_t name1_len, name2_len = 0;
- char *p;
CONF_SECTION *cs;
char buffer[1024];
if (!name1) return NULL;
- name1_len = strlen(name1) + 1;
if (name2) {
if (strchr(name2, '$')) {
name2 = cf_expand_variables(parent->item.filename,
return NULL;
}
}
- name2_len = strlen(name2) + 1;
}
- p = rad_malloc(sizeof(*cs) + name1_len + name2_len);
+ cs = talloc_zero(parent, CONF_SECTION);
+ if (!cs) return NULL;
- cs = (CONF_SECTION *) p;
- memset(cs, 0, sizeof(*cs));
cs->item.type = CONF_ITEM_SECTION;
cs->item.parent = parent;
- p += sizeof(*cs);
- memcpy(p, name1, name1_len);
- cs->name1 = p;
+ cs->name1 = talloc_strdup(cs, name1);
+ if (!cs->name1) {
+ error:
+ talloc_free(cs);
+ return NULL;
+ }
if (name2 && *name2) {
- p += name1_len;
- memcpy(p, name2, name2_len);
- cs->name2 = p;
+ cs->name2 = talloc_strdup(cs, name2);
+ if (!cs->name2) goto error;
}
cs->pair_tree = rbtree_create(pair_cmp, NULL, 0);
- if (!cs->pair_tree) {
- cf_section_free(&cs);
- return NULL;
- }
+ if (!cs->pair_tree) goto error;
+
+ talloc_set_destructor((void *) cs, cf_section_free);
/*
* Don't create a data tree, it may not be needed.
}
cf_log_info(cs, "\t%s = \"%s\"", name, value ? value : "(null)");
- *q = value ? strdup(value) : NULL;
+ *q = value ? talloc_strdup(cs, value) : NULL;
break;
/*
}
cf_log_info(cs, "\t%s = \"%s\"", name, value);
- *q = value ? strdup(value) : NULL;
+ *q = value ? talloc_strdup(cs, value) : NULL;
/*
* And now we "stat" the file.
cf_item_add(cs, &(cp->item));
if (cf_file_include(filename, cs) < 0) {
- cf_section_free(&cs);
+ talloc_free(cs);
return NULL;
}
return cs;
}
+
+void cf_file_free(CONF_SECTION *cs)
+{
+ talloc_free(cs);
+}
+
+
/*
* Return a CONF_PAIR within a CONF_SECTION.
*/
static CONF_DATA *cf_data_alloc(CONF_SECTION *parent, const char *name,
void *data, void (*data_free)(void *))
{
- char *p;
- size_t name_len;
CONF_DATA *cd;
- name_len = strlen(name) + 1;
-
- p = rad_malloc(sizeof(*cd) + name_len);
- cd = (CONF_DATA *) p;
- memset(cd, 0, sizeof(*cd));
+ cd = talloc_zero(parent, CONF_DATA);
+ if (!cd) return NULL;
cd->item.type = CONF_ITEM_DATA;
cd->item.parent = parent;
+ cd->name = talloc_strdup(cd, name);
+ if (!cd) {
+ talloc_free(cd);
+ return NULL;
+ }
+
cd->data = data;
cd->free = data_free;
- p += sizeof(*cd);
- memcpy(p, name, name_len);
- cd->name = p;
+ if (cd->free) {
+ talloc_set_destructor((void *) cd, cf_data_free);
+ }
+
return cd;
}