1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2025-01-03 14:56:34 -05:00

Fix: Fixed some smaller bugs such as leaks and performance improvements.

This is a first commit to correct minor problmes reported by
Denis Denisov. There is likely another commit to correct some more
such problems.

Thank you Denis Denisov.
This commit is contained in:
Philipp Schafft 2015-04-08 09:36:59 +00:00
parent 7402383448
commit c1f0eaff8a
9 changed files with 57 additions and 42 deletions

View File

@ -644,7 +644,6 @@ static void command_move_clients(client_t *client,
source_move_clients(source, dest);
memset(buf, '\000', sizeof(buf));
snprintf(buf, sizeof(buf), "Clients moved from %s to %s",
source->mount, dest_source);
xmlNewChild(node, NULL, XMLSTR("message"), XMLSTR(buf));
@ -687,7 +686,6 @@ static inline xmlNodePtr __add_listener(client_t *client,
if (tmp)
xmlNewChild(node, NULL, XMLSTR("referer"), XMLSTR(tmp));
memset(buf, '\000', sizeof(buf));
snprintf(buf, sizeof(buf), "%lu", (unsigned long)(now - client->con->con_time));
xmlNewChild(node, NULL, XMLSTR(mode == OMODE_LEGACY ? "Connected" : "connected"), XMLSTR(buf));

View File

@ -1955,7 +1955,6 @@ static void _parse_paths(xmlDocPtr doc,
free(alias);
continue;
}
temp = NULL;
temp = (char *)xmlGetProp(node, XMLSTR("port"));
if(temp != NULL) {
alias->port = atoi(temp);

View File

@ -212,23 +212,21 @@ static refbuf_t *ebml_get_buffer(source_t *source)
static int ebml_create_client_data(source_t *source, client_t *client)
{
ebml_client_data_t *ebml_client_data = calloc(1, sizeof(ebml_client_data_t));
ebml_client_data_t *ebml_client_data;
ebml_source_state_t *ebml_source_state = source->format->_state;
int ret = -1;
if (!ebml_source_state->header)
return -1;
if ((ebml_client_data) && (ebml_source_state->header))
{
ebml_client_data->header = ebml_source_state->header;
refbuf_addref(ebml_client_data->header);
client->format_data = ebml_client_data;
client->free_client_data = ebml_free_client_data;
ret = 0;
}
return ret;
ebml_client_data = calloc(1, sizeof(ebml_client_data_t));
if (!ebml_client_data)
return -1;
ebml_client_data->header = ebml_source_state->header;
refbuf_addref(ebml_client_data->header);
client->format_data = ebml_client_data;
client->free_client_data = ebml_free_client_data;
return 0;
}

View File

@ -277,12 +277,16 @@ static void mp3_set_title(source_t *source)
int r;
memset (p->data, '\0', size);
if (url_artist && url_title)
if (url_artist && url_title) {
r = snprintf (p->data, size, "%c%s%s - %s';", len_byte, streamtitle,
url_artist, url_title);
else
} else if (url_title) {
r = snprintf (p->data, size, "%c%s%s';", len_byte, streamtitle,
url_title);
} else {
r = snprintf (p->data, size, "%c%s';", len_byte, streamtitle);
}
if (r > 0)
{
if (source_mp3->inline_url)

View File

@ -150,16 +150,21 @@ int fserve_client_waiting (void)
/* only rebuild ufds if there are clients added/removed */
if (client_tree_changed)
{
client_tree_changed = 0;
ufds = realloc(ufds, fserve_clients * sizeof(struct pollfd));
fclient = active_list;
while (fclient)
{
ufds[i].fd = fclient->client->con->sock;
ufds[i].events = POLLOUT;
ufds[i].revents = 0;
fclient = fclient->next;
i++;
struct pollfd *ufds_new = realloc(ufds, fserve_clients * sizeof(struct pollfd));
/* REVIEW: If we can not allocate new ufds, keep old ones for now. */
if (ufds_new) {
ufds = ufds_new;
client_tree_changed = 0;
ufds = ufds_new;
fclient = active_list;
while (fclient)
{
ufds[i].fd = fclient->client->con->sock;
ufds[i].events = POLLOUT;
ufds[i].revents = 0;
fclient = fclient->next;
i++;
}
}
}
if (!ufds)
@ -466,6 +471,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
if (ret == -1 || ret >= (BUFSIZE - 512)) { /* we want at least 512 bytes left for the content of the playlist */
ICECAST_LOG_ERROR("Dropping client as we can not build response headers.");
client_send_error(httpclient, 500, 0, "Header generation failed.");
free(sourceuri);
return -1;
}
if (host == NULL)
@ -612,6 +618,7 @@ int fserve_client_create (client_t *httpclient, const char *path)
if (bytes == -1 || bytes >= (BUFSIZE - 512)) { /* we want at least 512 bytes left */
ICECAST_LOG_ERROR("Dropping client as we can not build response headers.");
client_send_error(httpclient, 500, 0, "Header generation failed.");
fclose(file);
return -1;
}
bytes += snprintf (httpclient->refbuf->data + bytes, BUFSIZE - bytes,

View File

@ -47,7 +47,7 @@ int playlistlog = 0;
int get_clf_time (char *buffer, unsigned len, struct tm *t)
{
char sign;
char *timezone_string;
char timezone_string[7];
struct tm gmt;
time_t time1 = time(NULL);
int time_days, time_hours, time_tz;
@ -65,6 +65,11 @@ int get_clf_time (char *buffer, unsigned len, struct tm *t)
#endif
/* FIXME: bail out if gmtime* returns NULL */
if (!thetime) {
snprintf(buffer, len, "<<BAD TIMESTAMP>>");
return 0;
}
time_days = t->tm_yday - gmt.tm_yday;
if (time_days < -1) {
@ -91,15 +96,13 @@ int get_clf_time (char *buffer, unsigned len, struct tm *t)
sign = '+';
}
timezone_string = calloc(1, 7);
snprintf(timezone_string, 7, " %c%.2d%.2d", sign, time_tz / 60, time_tz % 60);
snprintf(timezone_string, sizeof(timezone_string), " %c%.2d%.2d", sign, time_tz / 60, time_tz % 60);
now = time(NULL);
thetime = localtime(&now);
strftime (buffer, len-7, "%d/%b/%Y:%H:%M:%S", thetime);
strftime(buffer, len - sizeof(timezone_string), "%d/%b/%Y:%H:%M:%S", thetime);
strcat(buffer, timezone_string);
free(timezone_string);
return 1;
}
#endif

View File

@ -627,7 +627,6 @@ static void source_init (source_t *source)
strlen(":") + 6 + strlen(source->mount) + 1;
listenurl = malloc (listen_url_size);
memset (listenurl, '\000', listen_url_size);
snprintf (listenurl, listen_url_size, "http://%s:%d%s",
config->hostname, config->port, source->mount);
config_release_config();

View File

@ -333,7 +333,7 @@ void stats_event_add(const char *source, const char *name, unsigned long value)
if (event)
{
event->value = malloc (16);
snprintf (event->value, 16, "%ld", value);
snprintf(event->value, 16, "%lu", value);
event->action = STATS_EVENT_ADD;
queue_global_event (event);
}
@ -345,7 +345,7 @@ void stats_event_sub(const char *source, const char *name, unsigned long value)
if (event)
{
event->value = malloc (16);
snprintf (event->value, 16, "%ld", value);
snprintf(event->value, 16, "%lu", value);
event->action = STATS_EVENT_SUB;
queue_global_event (event);
}

View File

@ -563,7 +563,8 @@ static inline void _build_headers_loop(char **ret, size_t *len, ice_config_htt
size_t headerlen;
const char *name;
const char *value;
char * r = *ret;
char *r = *ret;
char *n;
if (!header)
return;
@ -590,11 +591,17 @@ static inline void _build_headers_loop(char **ret, size_t *len, ice_config_htt
/* append the header to the buffer */
headerlen = strlen(name) + strlen(value) + 4;
*len += headerlen;
r = realloc(r, *len);
strcat(r, name);
strcat(r, ": ");
strcat(r, value);
strcat(r, "\r\n");
n = realloc(r, *len);
if (n) {
r = n;
strcat(r, name);
strcat(r, ": ");
strcat(r, value);
strcat(r, "\r\n");
} else {
/* FIXME: we skip this header. We should do better. */
*len -= headerlen;
}
} while ((header = header->next));
*ret = r;
}