Store name and format string in internal state as their own copies rather than pointers to strings outside the state, for memory safety and to avoid a leak on remote control.
This commit is contained in:
+1
-1
@@ -130,7 +130,7 @@ bool opts_add_file(opts_t opts, const char *filename)
|
||||
* aren't copied anywhere, just the pointers are copied, so make sure the
|
||||
* command line data isn't overwritten or argv[1] free()d or whatever.
|
||||
*/
|
||||
/*@null@ *//*@only@ */
|
||||
/*@null@ */ /*@only@ */
|
||||
opts_t opts_parse(unsigned int argc, char **argv)
|
||||
{
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
|
||||
+2
-4
@@ -280,13 +280,11 @@ void pv_remote_check(pvstate_t state)
|
||||
msgbuf.name[sizeof(msgbuf.name) - 1] = '\0';
|
||||
msgbuf.format[sizeof(msgbuf.format) - 1] = '\0';
|
||||
|
||||
/* TODO: replace strdup(msgbuf.name) with just msgbuf.name once pv_state_* do their own strdup of name */
|
||||
|
||||
pv_state_set_format(state, msgbuf.progress, msgbuf.timer,
|
||||
msgbuf.eta, msgbuf.fineta, msgbuf.rate,
|
||||
msgbuf.average_rate,
|
||||
msgbuf.bytes, msgbuf.bufpercent,
|
||||
msgbuf.lastwritten, '\0' == msgbuf.name[0] ? NULL : strdup(msgbuf.name));
|
||||
msgbuf.lastwritten, '\0' == msgbuf.name[0] ? NULL : msgbuf.name);
|
||||
|
||||
if (msgbuf.rate_limit > 0)
|
||||
pv_state_rate_limit_set(state, msgbuf.rate_limit);
|
||||
@@ -302,7 +300,7 @@ void pv_remote_check(pvstate_t state)
|
||||
if (msgbuf.height > 0)
|
||||
pv_state_height_set(state, msgbuf.height);
|
||||
if (msgbuf.format[0] != '\0')
|
||||
pv_state_format_string_set(state, strdup(msgbuf.format));
|
||||
pv_state_format_string_set(state, msgbuf.format);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user