Skip to content

Commit

Permalink
review: fix malloc findings
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Mohr <[email protected]>
  • Loading branch information
alexmohr committed Sep 19, 2024
1 parent da50a13 commit cf63c53
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/daemon/dlt-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,10 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca
daemon->preconfigured_trace_load_settings_count = 0;
}
daemon->preconfigured_trace_load_settings = malloc(sizeof(DltTraceLoadSettings));
if (daemon->preconfigured_trace_load_settings == NULL) {
dlt_log(LOG_CRIT, "Failed to allocate memory for trace load settings\n");
return DLT_RETURN_ERROR;
}

/* open configuration file */
filename = daemon_local->flags.lvalue[0]
Expand Down Expand Up @@ -1247,10 +1251,10 @@ int trace_load_config_file_parser(DltDaemon *daemon, DltDaemonLocal *daemon_loca

DltTraceLoadSettings *settings = NULL;
int num_settings = 0;
DltReturnValue rv = dlt_daemon_find_preconfigured_trace_load_settings(
DltReturnValue find_trace_settings_return_value = dlt_daemon_find_preconfigured_trace_load_settings(
daemon, app_id_value, ctx_id_value, &settings, &num_settings,
0);
if (rv != DLT_RETURN_OK || num_settings != 0) {
if (find_trace_settings_return_value != DLT_RETURN_OK || num_settings != 0) {
dlt_vlog(LOG_WARNING,
"App id '%.4s' is already configured, or an error occurred, skipping entry\n",
app_id_value);
Expand Down
1 change: 1 addition & 0 deletions src/daemon/dlt-trace-load.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# SOFT_LIMIT and HARD_LIMIT are in byte/s
# Warnings will be issues in the interval configured via DLT_USER_HARD_LIMIT_OVER_MSG_INTERVAL
# the default for this is 1s
# The maximum for soft/hard limit is 2^32-1 (uint32 max)
#
# !!!!
# Note: this file is space separated, and wildcards are not supported
Expand Down
4 changes: 2 additions & 2 deletions src/daemon/dlt_daemon_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
if (application->trace_load_settings == NULL) {
DltTraceLoadSettings* pre_configured_trace_load_settings = NULL;
int num_settings = 0;
DltReturnValue rv = dlt_daemon_find_preconfigured_trace_load_settings(
DltReturnValue find_trace_settings_return_value = dlt_daemon_find_preconfigured_trace_load_settings(
daemon,
application->apid,
NULL /*load settings for all contexts*/,
Expand All @@ -781,7 +781,7 @@ DltDaemonApplication *dlt_daemon_application_add(DltDaemon *daemon,
verbose);

DltTraceLoadSettings *app_level = NULL;
if ((rv == DLT_RETURN_OK) &&
if ((find_trace_settings_return_value == DLT_RETURN_OK) &&
(pre_configured_trace_load_settings != NULL) &&
(num_settings != 0)) {
application->trace_load_settings = pre_configured_trace_load_settings;
Expand Down
10 changes: 10 additions & 0 deletions src/lib/dlt_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ DltReturnValue dlt_init(void)
pthread_rwlock_wrlock(&trace_load_rw_lock);

trace_load_settings = malloc(sizeof(DltTraceLoadSettings));
if (trace_load_settings == NULL) {
dlt_vlog(LOG_ERR, "Failed to allocate memory for trace load settings\n");
dlt_user_init_state = INIT_UNITIALIZED;
return DLT_RETURN_ERROR;
}
memset(trace_load_settings, 0, sizeof(DltTraceLoadSettings));
trace_load_settings[0].soft_limit = DLT_TRACE_LOAD_CLIENT_SOFT_LIMIT_DEFAULT;
trace_load_settings[0].hard_limit = DLT_TRACE_LOAD_CLIENT_HARD_LIMIT_DEFAULT;
Expand Down Expand Up @@ -4879,6 +4884,11 @@ DltReturnValue dlt_user_log_check_user_message(void)
char msg[255];
trace_load_settings_alloc_size = sizeof(DltTraceLoadSettings) * trace_load_settings_user_messages_count;
trace_load_settings = malloc(trace_load_settings_alloc_size);
if (trace_load_settings == NULL) {
pthread_rwlock_unlock(&trace_load_rw_lock);
dlt_log(LOG_ERR, "Failed to allocate memory for trace load settings\n");
return DLT_RETURN_ERROR;
}
memset(trace_load_settings, 0, trace_load_settings_alloc_size);
for (i = 0; i < trace_load_settings_user_messages_count; i++) {
strncpy(trace_load_settings[i].apid, dlt_user.appID, DLT_ID_SIZE);
Expand Down

0 comments on commit cf63c53

Please sign in to comment.