diff --git a/include/patty/ax25/if.h b/include/patty/ax25/if.h index e2238ca..9d6f370 100644 --- a/include/patty/ax25/if.h +++ b/include/patty/ax25/if.h @@ -43,7 +43,7 @@ typedef struct _patty_ax25_if { patty_list *addrs; } patty_ax25_if; -patty_ax25_if *patty_ax25_if_create(int opts, void *info); +patty_ax25_if *patty_ax25_if_new(int opts, void *info); void patty_ax25_if_destroy(patty_ax25_if *iface); diff --git a/include/patty/ax25/server.h b/include/patty/ax25/server.h index 0e35839..21137f6 100644 --- a/include/patty/ax25/server.h +++ b/include/patty/ax25/server.h @@ -6,7 +6,7 @@ typedef struct _patty_ax25_server patty_ax25_server; -int patty_ax25_server_init(patty_ax25_server *server); +patty_ax25_server *patty_ax25_server_new(); void patty_ax25_server_destroy(patty_ax25_server *server); diff --git a/src/Makefile b/src/Makefile index 54c4d72..c787134 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,7 +14,7 @@ HEADERS = kiss.h ax25.h ax25/if.h ax25/macros.h ax25/proto.h \ OBJS = kiss.o ax25.o if.o call.o frame.o server.o \ list.o hash.o dict.o -EXAMPLES = decode ptmx +EXAMPLES = decode ptmx testclient testserver HEADERS_BUILD = $(addprefix $(INCLUDE_PATH)/$(HEADER_SUBDIR)/, $(HEADERS)) diff --git a/src/if.c b/src/if.c index 0980073..4da2fd9 100644 --- a/src/if.c +++ b/src/if.c @@ -27,7 +27,7 @@ static void close_tnc(patty_ax25_if *iface) { patty_kiss_tnc_close(iface->tnc); } -patty_ax25_if *patty_ax25_if_create(int opts, void *info) { +patty_ax25_if *patty_ax25_if_new(int opts, void *info) { patty_ax25_if *iface; if ((iface = malloc(sizeof(*iface))) == NULL) { diff --git a/src/list.c b/src/list.c index 9e0f40e..9ca8c1c 100644 --- a/src/list.c +++ b/src/list.c @@ -55,7 +55,6 @@ void *patty_list_set(patty_list *list, off_t index, void *value) { } void *patty_list_append(patty_list *list, void *value) { - patty_list_item *item = list->first; patty_list_item *new; if ((new = malloc(sizeof(*new))) == NULL) { @@ -63,13 +62,14 @@ void *patty_list_append(patty_list *list, void *value) { } new->value = value; + new->next = NULL; if (list->first == NULL) { list->first = new; + list->last = new; } else { - for (item = list->first; item->next != NULL; item = item->next); - - item->next = new; + list->last->next = new; + list->last = new; } list->length++; diff --git a/src/server.c b/src/server.c index 7ba3242..1de60c5 100644 --- a/src/server.c +++ b/src/server.c @@ -35,7 +35,13 @@ struct _patty_ax25_server { *clients_by_sock; }; -int patty_ax25_server_init(patty_ax25_server *server) { +patty_ax25_server *patty_ax25_server_new() { + patty_ax25_server *server; + + if ((server = malloc(sizeof(*server))) == NULL) { + goto error_malloc_server; + } + memset(server, '\0', sizeof(*server)); if ((server->ifaces = patty_list_new()) == NULL) { @@ -66,7 +72,7 @@ int patty_ax25_server_init(patty_ax25_server *server) { goto error_dict_new_clients_by_sock; } - return 0; + return server; error_dict_new_clients_by_sock: patty_dict_destroy(server->clients); @@ -87,7 +93,10 @@ error_dict_new_socks_by_fd: patty_list_destroy(server->ifaces); error_list_new_ifaces: - return -1; + free(server); + +error_malloc_server: + return NULL; } static int destroy_if(patty_ax25_if *iface, void *ctx) { @@ -1105,4 +1114,6 @@ void patty_ax25_server_destroy(patty_ax25_server *server) { patty_ax25_server_each_if(server, destroy_if, NULL); patty_list_destroy(server->ifaces); + + free(server); }