[lttng-dev] [PATCH lttng-tools 13/14] Remove malloc in fscanf since it is not supported on all platforms.

Charles Briere charlesbriere.flatzo at gmail.com
Mon May 6 14:18:50 EDT 2013


From: Pierre-Luc St-Charles <pierre-luc.st-charles at polymtl.ca>

Signed-off-by: Pierre-Luc St-Charles <pierre-luc.st-charles at polymtl.ca>
---
 src/bin/lttng-sessiond/kernel.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c
index 856d423..ed9e221 100644
--- a/src/bin/lttng-sessiond/kernel.c
+++ b/src/bin/lttng-sessiond/kernel.c
@@ -591,7 +591,7 @@ error:
 ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
 {
 	int fd, pos, ret;
-	char *event;
+	char event[LTTNG_SYMBOL_NAME_LEN];
 	size_t nbmem, count = 0;
 	FILE *fp;
 	struct lttng_event *elist;
@@ -622,7 +622,7 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
 		goto end;
 	}
 
-	while (fscanf(fp, "event { name = %m[^;]; };%n\n", &event, &pos) == 1) {
+	while (fscanf(fp, "event { name = %[^;]; };%n\n", &event, &pos) == 1) {
 		if (count >= nbmem) {
 			struct lttng_event *new_elist;
 
@@ -633,7 +633,6 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
 			new_elist = realloc(elist, nbmem * sizeof(struct lttng_event));
 			if (new_elist == NULL) {
 				PERROR("realloc list events");
-				free(event);
 				free(elist);
 				count = -ENOMEM;
 				goto end;
@@ -644,7 +643,6 @@ ssize_t kernel_list_events(int tracer_fd, struct lttng_event **events)
 		elist[count].name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
 		elist[count].enabled = -1;
 		count++;
-		free(event);
 	}
 
 	*events = elist;
-- 
1.8.1.msysgit.1




More information about the lttng-dev mailing list