Clean up dynamic fields when closing a port.

In the course of development we added more and more allocations into the
port code without freeing them on close. We do not yet call the close
function, so there was never an issue. Once we start to reset the ports,
to clear faults for example, then we will need this.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
master
Richard Cochran 2012-03-13 09:11:01 +01:00
parent 29463cd306
commit 9c9dc35f13
1 changed files with 19 additions and 0 deletions

19
port.c
View File

@ -246,6 +246,16 @@ static int add_foreign_master(struct port *p, struct ptp_message *m)
return broke_threshold || diff; return broke_threshold || diff;
} }
static void free_foreign_masters(struct port *p)
{
struct foreign_clock *fc;
while ((fc = LIST_FIRST(&p->foreign_masters)) != NULL) {
LIST_REMOVE(fc, list);
fc_clear(fc);
free(fc);
}
}
static int port_clr_tmo(int fd) static int port_clr_tmo(int fd)
{ {
struct itimerspec tmo = { struct itimerspec tmo = {
@ -782,6 +792,15 @@ static void process_sync(struct port *p, struct ptp_message *m)
void port_close(struct port *p) void port_close(struct port *p)
{ {
int i; int i;
if (p->last_follow_up)
msg_put(p->last_follow_up);
if (p->last_sync)
msg_put(p->last_sync);
if (p->delay_req)
msg_put(p->delay_req);
free_foreign_masters(p);
transport_close(p->trp, &p->fda); transport_close(p->trp, &p->fda);
transport_destroy(p->trp); transport_destroy(p->trp);
for (i = 0; i < N_TIMER_FDS; i++) { for (i = 0; i < N_TIMER_FDS; i++) {