summaryrefslogtreecommitdiff
path: root/src/lib/dlt_user.c
diff options
context:
space:
mode:
authorlti9hc <114125133+lti9hc@users.noreply.github.com>2022-10-26 15:11:24 +0700
committerGitHub <noreply@github.com>2022-10-26 10:11:24 +0200
commit948ed9928d933bbbfbb704ab0cc2296cb4333055 (patch)
treed18c533ba25de25a11e6ad2779305d14d19bdfeb /src/lib/dlt_user.c
parent0f969a93770b2261b6d18b9296263f0deaf134bd (diff)
downloadDLT-daemon-948ed9928d933bbbfbb704ab0cc2296cb4333055.tar.gz
Fix for Resource and Memory Leak (#418)
dlt_daemon_client.c Adding NULL check for tok dlt_daemon_offline_logstorage.c : Adding NULL check for application dlt_user.c : Fix for Memory Leak dlt-daemon.c : Fix for Resource Leak dlt_config_file_parser.c : Add termination character at the end of string dlt_offline_trace.c : Fix for Resource Leak Signed-off-by: Mvaradaraj2 manoj.varadaraj2@harman.com Co-authored-by: Le Tin <tin.le@vn.bosch.com>
Diffstat (limited to 'src/lib/dlt_user.c')
-rw-r--r--src/lib/dlt_user.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 99df11b..0085593 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -1813,27 +1813,34 @@ DltReturnValue dlt_user_log_write_start_internal(DltContext *handle,
ret = dlt_user_log_write_start_init(handle, log, loglevel, is_verbose);
if (ret == DLT_RETURN_TRUE) {
/* initialize values */
- if (log->buffer == NULL) {
+ if ((NULL != log->buffer))
+ {
+ free(log->buffer);
+ log->buffer = NULL;
+ }
+ else
+ {
log->buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len);
-
- if (log->buffer == NULL) {
- dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n");
- return DLT_RETURN_ERROR;
- }
}
- /* In non-verbose mode, insert message id */
- if (!is_verbose_mode(dlt_user.verbose_mode, log)) {
- if ((sizeof(uint32_t)) > dlt_user.log_buf_len) {
- return DLT_RETURN_USER_BUFFER_FULL;
- }
+ if (log->buffer == NULL) {
+ dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n");
+ return DLT_RETURN_ERROR;
+ }
+ else
+ {
+ /* In non-verbose mode, insert message id */
+ if (!is_verbose_mode(dlt_user.verbose_mode, log)) {
+ if ((sizeof(uint32_t)) > dlt_user.log_buf_len)
+ return DLT_RETURN_USER_BUFFER_FULL;
- /* Write message id */
- memcpy(log->buffer, &(messageid), sizeof(uint32_t));
- log->size = sizeof(uint32_t);
+ /* Write message id */
+ memcpy(log->buffer, &(messageid), sizeof(uint32_t));
+ log->size = sizeof(uint32_t);
- /* as the message id is part of each message in non-verbose mode,
- * it doesn't increment the argument counter in extended header (if used) */
+ /* as the message id is part of each message in non-verbose mode,
+ * it doesn't increment the argument counter in extended header (if used) */
+ }
}
}
@@ -1874,7 +1881,7 @@ DltReturnValue dlt_user_log_write_start_w_given_buffer(DltContext *handle,
return ret;
}
-
+
DltReturnValue dlt_user_log_write_finish(DltContextData *log)
{
int ret = DLT_RETURN_ERROR;