Skip to content

Commit

Permalink
use static buffer for get_uptime_string call
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarning committed Mar 13, 2019
1 parent 59cec60 commit 4a85989
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/http_microhttpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,9 @@ static void replace_variables(
char maxclients[12];
char clientupload[20];
char clientdownload[20];
char uptime[64];

const char *redirect_url = NULL;
char *uptime = NULL;
char *denyaction = NULL;
char *authaction = NULL;
char *authtarget = NULL;
Expand All @@ -1007,7 +1007,7 @@ static void replace_variables(
sprintf(clientupload, "%llu", client->counters.outgoing);
sprintf(clientdownload, "%llu", client->counters.incoming);

uptime = get_uptime_string();
get_uptime_string(uptime);
redirect_url = get_redirect_url(connection);

sprintf(nclients, "%d", get_client_list_length());
Expand Down Expand Up @@ -1043,7 +1043,6 @@ static void replace_variables(

tmpl_parse(vars, dst, dst_len, src, src_len);

free(uptime);
free(denyaction);
free(authaction);
free(authtarget);
Expand Down
4 changes: 1 addition & 3 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,9 @@ format_time(time_t time, char buf[64])
return buf;
}

/* Caller must free. */
char *
get_uptime_string()
get_uptime_string(char buf[64])
{
char *buf = malloc(64);
return format_duration(started_time, time(NULL), buf);
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ char *format_time(time_t time, char buf[64]);
/*
* @brief Mallocs and returns nodogsplash uptime string
*/
char *get_uptime_string();
char *get_uptime_string(char buf[64]);
/*
* @brief Writes a human-readable paragraph of the status of the nodogsplash process
*/
Expand Down

0 comments on commit 4a85989

Please sign in to comment.