diff --git a/src/client.c b/src/client.c index b7f8a73a..ceb83f74 100644 --- a/src/client.c +++ b/src/client.c @@ -63,6 +63,10 @@ void client_destroy(client_t *client) while ((refbuf = refbuf_queue_remove(&client->queue))) refbuf_release(refbuf); + /* we need to free client specific format data (if any) */ + if (client->free_client_data) + client->free_client_data (client); + free(client->username); free(client); diff --git a/src/client.h b/src/client.h index 7f0e9c8e..d38d9677 100644 --- a/src/client.h +++ b/src/client.h @@ -42,6 +42,9 @@ typedef struct _client_tag /* Format-handler-specific data for this client */ void *format_data; + + /* function to call to release format specific resources */ + void (*free_client_data)(struct _client_tag *client); } client_t; client_t *client_create(connection_t *con, http_parser_t *parser); diff --git a/src/format_mp3.c b/src/format_mp3.c index affa8ad3..4231d58b 100644 --- a/src/format_mp3.c +++ b/src/format_mp3.c @@ -59,6 +59,7 @@ static int format_mp3_get_buffer(format_plugin_t *self, char *data, static refbuf_queue_t *format_mp3_get_predata(format_plugin_t *self); static void *format_mp3_create_client_data(format_plugin_t *self, source_t *source, client_t *client); +static void free_mp3_client_data (client_t *client); static int format_mp3_write_buf_to_client(format_plugin_t *self, client_t *client, unsigned char *buf, int len); static void format_mp3_send_headers(format_plugin_t *self, @@ -394,6 +395,7 @@ static void *format_mp3_create_client_data(format_plugin_t *self, data->interval = ICY_METADATA_INTERVAL; data->offset = 0; + client->free_client_data = free_mp3_client_data; metadata = httpp_getvar(client->parser, "icy-metadata"); if(metadata) @@ -402,6 +404,14 @@ static void *format_mp3_create_client_data(format_plugin_t *self, return data; } + +static void free_mp3_client_data (client_t *client) +{ + free (client->format_data); + client->format_data = NULL; +} + + static void format_mp3_send_headers(format_plugin_t *self, source_t *source, client_t *client) {