Clear memory allocated by ralloc().

This also fixes bug that timer->recurrent was not cleared
in tm_new() and unexpected recurrence of startup timer
in BGP confused state machine and caused crash.
This commit is contained in:
Ondrej Zajicek 2009-09-04 11:24:08 +02:00
parent 05198c12f4
commit daeeb8e982
4 changed files with 4 additions and 28 deletions

View file

@ -63,10 +63,6 @@ event *
ev_new(pool *p) ev_new(pool *p)
{ {
event *e = ralloc(p, &ev_class); event *e = ralloc(p, &ev_class);
e->hook = NULL;
e->data = NULL;
e->n.next = NULL;
return e; return e;
} }

View file

@ -64,13 +64,9 @@ linpool
*lp_new(pool *p, unsigned blk) *lp_new(pool *p, unsigned blk)
{ {
linpool *m = ralloc(p, &lp_class); linpool *m = ralloc(p, &lp_class);
m->ptr = m->end = NULL;
m->first = m->current = NULL;
m->plast = &m->first; m->plast = &m->first;
m->first_large = NULL;
m->chunk_size = blk; m->chunk_size = blk;
m->threshold = 3*blk/4; m->threshold = 3*blk/4;
m->total = m->total_large = 0;
return m; return m;
} }

View file

@ -183,13 +183,14 @@ rdump(void *res)
* *
* This function is called by the resource classes to create a new * This function is called by the resource classes to create a new
* resource of the specified class and link it to the given pool. * resource of the specified class and link it to the given pool.
* Size of the resource structure is taken from the @size field * Allocated memory is zeroed. Size of the resource structure is taken
* of the &resclass. * from the @size field of the &resclass.
*/ */
void * void *
ralloc(pool *p, struct resclass *c) ralloc(pool *p, struct resclass *c)
{ {
resource *r = xmalloc(c->size); resource *r = xmalloc(c->size);
bzero(r, c->size);
r->class = c; r->class = c;
add_tail(&p->inside, &r->n); add_tail(&p->inside, &r->n);

View file

@ -205,10 +205,6 @@ timer *
tm_new(pool *p) tm_new(pool *p)
{ {
timer *t = ralloc(p, &tm_class); timer *t = ralloc(p, &tm_class);
t->hook = NULL;
t->data = NULL;
t->randomize = 0;
t->expires = 0;
return t; return t;
} }
@ -595,22 +591,9 @@ sk_new(pool *p)
{ {
sock *s = ralloc(p, &sk_class); sock *s = ralloc(p, &sk_class);
s->pool = p; s->pool = p;
s->data = NULL; // s->saddr = s->daddr = IPA_NONE;
s->saddr = s->daddr = IPA_NONE;
s->sport = s->dport = 0;
s->tos = s->ttl = -1; s->tos = s->ttl = -1;
s->flags = 0;
s->iface = NULL;
s->rbuf = NULL;
s->rx_hook = NULL;
s->rbsize = 0;
s->tbuf = NULL;
s->tx_hook = NULL;
s->tbsize = 0;
s->err_hook = NULL;
s->fd = -1; s->fd = -1;
s->rbuf_alloc = s->tbuf_alloc = NULL;
s->password = NULL;
return s; return s;
} }