Skip to contentSkip to conversation

Fix: Memory leaks on error paths in config_read_session_name

PATCH New Christian Babeux 2 participants 7 messages Feb 28, 2013 – Mar 21, 2013 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 Fix: Memory leaks on error paths in config_read_session_name

---
 src/bin/lttng/conf.c | 2 ++
 1 file changed, 2 insertions(+)
src/bin/lttng/conf.c +2 -0
index c1bfcfd..7439c1c 100644
@@ -203,6 +203,7 @@ char *config_read_session_name(char *path)
 	if (fp == NULL) {
 		ERR("Can't find valid lttng config %s/.lttngrc", path);
 		MSG("Did you create a session? (lttng create <my_session>)");
+		free(session_name);
 		goto error;
 	}
 
@@ -221,6 +222,7 @@ char *config_read_session_name(char *path)
 	}
 
 error_close:
+	free(session_name);
 	ret = fclose(fp);
 	if (ret < 0) {
 		PERROR("close config read session name");
Signature · 1 line
1.8.1.3
#2 lore raw

PATCH 1/1 Fix: Memory leaks on error paths when exporting consumerd libdir in env

In reply to a message not in the archive
---
 src/bin/lttng-sessiond/main.c | 2 ++
 1 file changed, 2 insertions(+)
src/bin/lttng-sessiond/main.c +2 -0
index e9529f1..82f0a84 100644
@@ -1798,6 +1798,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
 				ret = putenv(tmpnew);
 				if (ret) {
 					ret = -errno;
+					free(tmpnew);
 					goto error;
 				}
 			}
@@ -1842,6 +1843,7 @@ static pid_t spawn_consumerd(struct consumer_data *consumer_data)
 				ret = putenv(tmpnew);
 				if (ret) {
 					ret = -errno;
+					free(tmpnew);
 					goto error;
 				}
 			}
Signature · 1 line
1.8.1.3
#3 lore raw

PATCH 1/1 Fix: Memory leaks on unknown hashtable type error handling

In reply to a message not in the archive
---
 src/common/hashtable/hashtable.c | 1 +
 1 file changed, 1 insertion(+)
src/common/hashtable/hashtable.c +1 -0
index 24d5797..5bf85e5 100644
@@ -90,6 +90,7 @@ struct lttng_ht *lttng_ht_new(unsigned long size, int type)
 		break;
 	default:
 		ERR("Unknown lttng hashtable type %d", type);
+		lttng_ht_destroy(ht);
 		goto error;
 	}
 
Signature · 1 line
1.8.1.3
#4 lore raw

PATCH 1/1 Fix: Memory leaks when calling get_cmdline_by_pid

In reply to a message not in the archive

Callers of get_cmdline_by_pid must free(3) the returned string.

---
 src/bin/lttng/commands/list.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
src/bin/lttng/commands/list.c +9 -2
index 8fec91f..5429df4 100644
@@ -294,6 +294,7 @@ static int list_ust_events(void)
 	struct lttng_handle *handle;
 	struct lttng_event *event_list;
 	pid_t cur_pid = 0;
+	char *cmdline = NULL;
 
 	memset(&domain, 0, sizeof(domain));
 
@@ -322,7 +323,9 @@ static int list_ust_events(void)
 	for (i = 0; i < size; i++) {
 		if (cur_pid != event_list[i].pid) {
 			cur_pid = event_list[i].pid;
-			MSG("\nPID: %d - Name: %s", cur_pid, get_cmdline_by_pid(cur_pid));
+			cmdline = get_cmdline_by_pid(cur_pid);
+			MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
+			free(cmdline);
 		}
 		print_events(&event_list[i]);
 	}
@@ -349,6 +352,8 @@ static int list_ust_event_fields(void)
 	struct lttng_handle *handle;
 	struct lttng_event_field *event_field_list;
 	pid_t cur_pid = 0;
+	char *cmdline = NULL;
+
 	struct lttng_event cur_event;
 
 	memset(&domain, 0, sizeof(domain));
@@ -379,7 +384,9 @@ static int list_ust_event_fields(void)
 	for (i = 0; i < size; i++) {
 		if (cur_pid != event_field_list[i].event.pid) {
 			cur_pid = event_field_list[i].event.pid;
-			MSG("\nPID: %d - Name: %s", cur_pid, get_cmdline_by_pid(cur_pid));
+			cmdline = get_cmdline_by_pid(cur_pid);
+			MSG("\nPID: %d - Name: %s", cur_pid, cmdline);
+			free(cmdline);
 		}
 		if (strcmp(cur_event.name, event_field_list[i].event.name) != 0) {
 			print_events(&event_field_list[i].event);
Signature · 1 line
1.8.1.3
#5 lore raw

PATCH 1/1 Fix: Memory leak when zmalloc fail on kernel channel allocation

In reply to a message not in the archive
---
 src/bin/lttng-sessiond/trace-kernel.c | 1 +
 1 file changed, 1 insertion(+)
src/bin/lttng-sessiond/trace-kernel.c +1 -0
index 48be065..8839a00 100644
@@ -158,6 +158,7 @@ struct ltt_kernel_channel *trace_kernel_create_channel(
 	lkc->channel = zmalloc(sizeof(struct lttng_channel));
 	if (lkc->channel == NULL) {
 		PERROR("lttng_channel zmalloc");
+		free(lkc);
 		goto error;
 	}
 	memcpy(lkc->channel, chan, sizeof(struct lttng_channel));
Signature · 1 line
1.8.1.3
#6 lore raw

PATCH 1/1 Fix: Use after free on spawn_sessiond error path in check_sessiond

In reply to a message not in the archive
---
 src/bin/lttng/lttng.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
src/bin/lttng/lttng.c +2 -3
index 8562144..be673f9 100644
@@ -374,13 +374,12 @@ static int check_sessiond(void)
 		}
 
 		ret = spawn_sessiond(pathname);
-		free(alloc_pathname);
 		if (ret < 0) {
 			ERR("Problem occurred when starting %s", pathname);
-			goto end;
 		}
-	}
 
+		free(alloc_pathname);
+	}
 end:
 	return ret;
 }
Signature · 1 line
1.8.1.3
#7 lore raw

Re: [PATCH lttng-tools] Fix: Memory leak on error paths of relay_add_stream

In reply to a message not in the archive

Merged all 7!

David

Christian Babeux:

Quoted 43 lines

On error paths the memory allocated for stream is never freed.

Also, fix undefined behavior on asprintf alloc failure. According to asprintf(3), the content of the pointer passed to it is undefined if an alloc failure occurs, so we could end up freeing a pointer in an undefined state. Force its value to NULL.

---
 src/bin/lttng-relayd/main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
src/bin/lttng-relayd/main.c +6 -1
index 4f9d742..00b7ea3 100644
@@ -941,6 +941,7 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr,
 	ret = asprintf(&path, "%s/%s", root_path, stream_info.channel_name);
 	if (ret < 0) {
 		PERROR("asprintf stream path");
+		path = NULL;
 		goto end;
 	}
 
@@ -963,13 +964,17 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr,
 end:
 	free(path);
 	free(root_path);
+
+	reply.handle = htobe64(stream->stream_handle);
 	/* send the session id to the client or a negative return code on error */
 	if (ret < 0) {
 		reply.ret_code = htobe32(LTTNG_ERR_UNK);
+		/* stream was not properly added to the ht, so free it */
+		free(stream);
 	} else {
 		reply.ret_code = htobe32(LTTNG_OK);
 	}
-	reply.handle = htobe64(stream->stream_handle);
+
 	send_ret = cmd->sock->ops->sendmsg(cmd->sock, &reply,
 			sizeof(struct lttcomm_relayd_status_stream), 0);
 	if (send_ret < 0) {