Message ID | 20201112091109.1239169-3-tz.stoyanov@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | libtracefs fixes and improvements | expand |
On Thu, 12 Nov 2020 11:11:05 +0200 "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote: > The tracefs_instance_get_name() API returns a pointer to internal > string. This string is not meant to be changed by the API callers, > that's why it should be constant. > > Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> > --- > include/tracefs/tracefs.h | 2 +- > lib/tracefs/tracefs-events.c | 12 ++---------- > lib/tracefs/tracefs-instance.c | 2 +- > tracecmd/trace-record.c | 2 +- > utest/tracefs-utest.c | 2 +- > 5 files changed, 6 insertions(+), 14 deletions(-) > > diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h > index 8ee7ba6e..1cf8de48 100644 > --- a/include/tracefs/tracefs.h > +++ b/include/tracefs/tracefs.h > @@ -24,7 +24,7 @@ struct tracefs_instance *tracefs_instance_alloc(const char *name); > void tracefs_instance_free(struct tracefs_instance *instance); > int tracefs_instance_create(struct tracefs_instance *instance); > int tracefs_instance_destroy(struct tracefs_instance *instance); > -char *tracefs_instance_get_name(struct tracefs_instance *instance); > +const char *tracefs_instance_get_name(struct tracefs_instance *instance); > char * > tracefs_instance_get_file(struct tracefs_instance *instance, const char *file); > char *tracefs_instance_get_dir(struct tracefs_instance *instance); > diff --git a/lib/tracefs/tracefs-events.c b/lib/tracefs/tracefs-events.c > index 8e825f50..6b796382 100644 > --- a/lib/tracefs/tracefs-events.c > +++ b/lib/tracefs/tracefs-events.c > @@ -481,11 +481,7 @@ next_event: > failure = ret; > } > > - if (events) { > - for (i = 0; events[i]; i++) > - free(events[i]); > - free(events); > - } > + tracefs_list_free(events); > return failure; > } > > @@ -564,11 +560,7 @@ static int fill_local_events_system(const char *tracing_dir, > /* always succeed because parsing failures are not critical */ > ret = 0; > out: > - if (systems) { > - for (i = 0; systems[i]; i++) > - free(systems[i]); > - free(systems); > - } > + tracefs_list_free(systems); > return ret; > } > The above looks like it belongs in its own patch (not related to this change). -- Steve
diff --git a/include/tracefs/tracefs.h b/include/tracefs/tracefs.h index 8ee7ba6e..1cf8de48 100644 --- a/include/tracefs/tracefs.h +++ b/include/tracefs/tracefs.h @@ -24,7 +24,7 @@ struct tracefs_instance *tracefs_instance_alloc(const char *name); void tracefs_instance_free(struct tracefs_instance *instance); int tracefs_instance_create(struct tracefs_instance *instance); int tracefs_instance_destroy(struct tracefs_instance *instance); -char *tracefs_instance_get_name(struct tracefs_instance *instance); +const char *tracefs_instance_get_name(struct tracefs_instance *instance); char * tracefs_instance_get_file(struct tracefs_instance *instance, const char *file); char *tracefs_instance_get_dir(struct tracefs_instance *instance); diff --git a/lib/tracefs/tracefs-events.c b/lib/tracefs/tracefs-events.c index 8e825f50..6b796382 100644 --- a/lib/tracefs/tracefs-events.c +++ b/lib/tracefs/tracefs-events.c @@ -481,11 +481,7 @@ next_event: failure = ret; } - if (events) { - for (i = 0; events[i]; i++) - free(events[i]); - free(events); - } + tracefs_list_free(events); return failure; } @@ -564,11 +560,7 @@ static int fill_local_events_system(const char *tracing_dir, /* always succeed because parsing failures are not critical */ ret = 0; out: - if (systems) { - for (i = 0; systems[i]; i++) - free(systems[i]); - free(systems); - } + tracefs_list_free(systems); return ret; } diff --git a/lib/tracefs/tracefs-instance.c b/lib/tracefs/tracefs-instance.c index 50e88534..e37d93d1 100644 --- a/lib/tracefs/tracefs-instance.c +++ b/lib/tracefs/tracefs-instance.c @@ -169,7 +169,7 @@ char *tracefs_instance_get_dir(struct tracefs_instance *instance) * Returns the name of the given @instance. * The returned string must *not* be freed. */ -char *tracefs_instance_get_name(struct tracefs_instance *instance) +const char *tracefs_instance_get_name(struct tracefs_instance *instance) { if (instance) return instance->name; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 72a5c8c9..8cd44dd0 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -3861,7 +3861,7 @@ static void connect_to_agent(struct buffer_instance *instance) unsigned int *ports; int i, *fds = NULL; bool use_fifos = false; - char *name; + const char *name; name = tracefs_instance_get_name(instance->tracefs); if (!no_fifos) { diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index 1c146576..b5296963 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -180,7 +180,7 @@ static void test_instance_file(void) { struct tracefs_instance *instance = NULL; const char *name = get_rand_str(); - char *inst_name = NULL; + const char *inst_name = NULL; const char *tdir; char *inst_file; char *inst_dir;
The tracefs_instance_get_name() API returns a pointer to internal string. This string is not meant to be changed by the API callers, that's why it should be constant. Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com> --- include/tracefs/tracefs.h | 2 +- lib/tracefs/tracefs-events.c | 12 ++---------- lib/tracefs/tracefs-instance.c | 2 +- tracecmd/trace-record.c | 2 +- utest/tracefs-utest.c | 2 +- 5 files changed, 6 insertions(+), 14 deletions(-)