main() reintroducing strncat() instead of util_concat()
WIP: memory leaks evaluation
This commit is contained in:
parent
794418e208
commit
d261ffee30
|
@ -175,6 +175,12 @@ enum fsm_enum_log_source {
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define FILE_SOURCE_NAME_SIZE 40
|
||||||
|
#define FUNCTION_SOURCE_NAME_SIZE 40
|
||||||
|
#define STRING_VALUE_SIZE 60
|
||||||
|
#define LOG_MAX_LENGTH 255 /**< arbitrary */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A log unit must include the followings:
|
* A log unit must include the followings:
|
||||||
*
|
*
|
||||||
|
@ -217,12 +223,12 @@ struct fsm_log_t
|
||||||
void fsm_init_log (struct fsm_log_t *);
|
void fsm_init_log (struct fsm_log_t *);
|
||||||
void fsm_publish_log (struct fsm_log_t *);
|
void fsm_publish_log (struct fsm_log_t *);
|
||||||
void fsm_clear_log (struct fsm_log_t *);
|
void fsm_clear_log (struct fsm_log_t *);
|
||||||
void fsm_clear_log_unit (struct fsm_log_unit_t *);
|
void fsm_clear_log_unit(struct fsm_log_unit_t *);
|
||||||
|
|
||||||
void fsm_add_log_event (struct fsm_log_t *gg_logs,
|
void fsm_add_log_event (struct fsm_log_t *gg_logs,
|
||||||
const char *file_source,
|
const char *file_source,
|
||||||
const char *function_source,
|
const char *function_source,
|
||||||
char *string_value);
|
const char *string_value);
|
||||||
|
|
||||||
int fsm_get_log_length(struct fsm_log_t *);
|
int fsm_get_log_length(struct fsm_log_t *);
|
||||||
void fsm_seek_log (struct fsm_log_t *gg_logs,
|
void fsm_seek_log (struct fsm_log_t *gg_logs,
|
||||||
|
@ -239,7 +245,7 @@ void fsm_add_log (int severity,
|
||||||
int source,
|
int source,
|
||||||
const char *file_source,
|
const char *file_source,
|
||||||
const char *function_source,
|
const char *function_source,
|
||||||
char *string_value);
|
const char *string_value);
|
||||||
|
|
||||||
void fsm_relay_init_log();
|
void fsm_relay_init_log();
|
||||||
void fsm_relay_close_log();
|
void fsm_relay_close_log();
|
||||||
|
|
|
@ -96,7 +96,7 @@ void fsm_add_log (int severity,
|
||||||
int source,
|
int source,
|
||||||
const char *file_source,
|
const char *file_source,
|
||||||
const char *function_source,
|
const char *function_source,
|
||||||
char *string_value)
|
const char *string_value)
|
||||||
{
|
{
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
|
|
|
@ -43,9 +43,6 @@
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include "../../../include/fsm.h"
|
#include "../../../include/fsm.h"
|
||||||
|
|
||||||
static int string_1_size = 40;
|
|
||||||
static int string_2_size = 40;
|
|
||||||
static int string_3_size = 50;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inits the log: a double chained list.
|
* Inits the log: a double chained list.
|
||||||
|
@ -104,7 +101,7 @@ void fsm_clear_log_unit (struct fsm_log_unit_t *unit)
|
||||||
/**
|
/**
|
||||||
* Adds a log unit (an event) to the log list.
|
* Adds a log unit (an event) to the log list.
|
||||||
*
|
*
|
||||||
* *new_unit = malloc (sizeof (fsm_log_unit_struct));
|
* new_unit = malloc (sizeof (fsm_log_unit_struct));
|
||||||
*
|
*
|
||||||
* warn: is never free (as new log units are never removed)
|
* warn: is never free (as new log units are never removed)
|
||||||
*
|
*
|
||||||
|
@ -118,7 +115,7 @@ void fsm_clear_log_unit (struct fsm_log_unit_t *unit)
|
||||||
void fsm_add_log_event (struct fsm_log_t *gg_logs,
|
void fsm_add_log_event (struct fsm_log_t *gg_logs,
|
||||||
const char *file_source,
|
const char *file_source,
|
||||||
const char *function_source,
|
const char *function_source,
|
||||||
char *string_value)
|
const char *string_value)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday (&tv, NULL);
|
gettimeofday (&tv, NULL);
|
||||||
|
@ -129,30 +126,28 @@ void fsm_add_log_event (struct fsm_log_t *gg_logs,
|
||||||
new_unit->yy_dd_mm = tv.tv_sec;
|
new_unit->yy_dd_mm = tv.tv_sec;
|
||||||
new_unit->usec = tv.tv_usec;
|
new_unit->usec = tv.tv_usec;
|
||||||
|
|
||||||
new_unit->file_source = malloc(string_1_size * sizeof(char));
|
new_unit->file_source = malloc(FILE_SOURCE_NAME_SIZE * sizeof(char));
|
||||||
new_unit->function_source = malloc(string_2_size * sizeof(char));
|
new_unit->function_source = malloc(FUNCTION_SOURCE_NAME_SIZE * sizeof(char));
|
||||||
new_unit->string_value = malloc(string_3_size * sizeof(char));
|
new_unit->string_value = malloc(STRING_VALUE_SIZE * sizeof(char));
|
||||||
|
|
||||||
strncpy (new_unit->file_source, file_source, string_1_size - 1);
|
strncpy (new_unit->file_source, file_source, FILE_SOURCE_NAME_SIZE - 1);
|
||||||
strncpy (new_unit->function_source, function_source, string_2_size - 1);
|
strncpy (new_unit->function_source, function_source, FUNCTION_SOURCE_NAME_SIZE - 1);
|
||||||
strncpy (new_unit->string_value, string_value, string_3_size - 1);
|
strncpy (new_unit->string_value, string_value, STRING_VALUE_SIZE - 1);
|
||||||
|
|
||||||
// first time we log something (don't touch new_unit->prev)
|
/** first time we log something (don't touch new_unit->prev) */
|
||||||
if (gg_logs->oldest == NULL)
|
if (gg_logs->oldest == NULL)
|
||||||
gg_logs->oldest = new_unit; // record the first reference (once)
|
gg_logs->oldest = new_unit; /**< record the first reference (once) */
|
||||||
// not the first time, just update
|
/**< not the first time, just update */
|
||||||
else {
|
else {
|
||||||
new_unit->prev = gg_logs->latest;
|
new_unit->prev = gg_logs->latest;
|
||||||
new_unit->prev->next = new_unit;
|
new_unit->prev->next = new_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// in any case, update the latest reference
|
/**< in any case, update the latest reference */
|
||||||
gg_logs->latest = new_unit;
|
gg_logs->latest = new_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define LOG_MAX_LENGTH 255 /**< arbitrary */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publishes all the logs chronologically (using the g_lib function: g_message)
|
* Publishes all the logs chronologically (using the g_lib function: g_message)
|
||||||
*
|
*
|
||||||
|
@ -173,7 +168,7 @@ void fsm_publish_log (struct fsm_log_t *gg_logs)
|
||||||
strftime(timestamp, LOG_MAX_LENGTH * sizeof(char),
|
strftime(timestamp, LOG_MAX_LENGTH * sizeof(char),
|
||||||
"%D %T", localtime(&a_unit->yy_dd_mm));
|
"%D %T", localtime(&a_unit->yy_dd_mm));
|
||||||
|
|
||||||
g_message ("%s + %-6ld %6d %-28s %-32s %-45s",
|
g_message ("%s + %-6ld %6d %-28s %-32s %-60s",
|
||||||
timestamp,
|
timestamp,
|
||||||
a_unit->usec,
|
a_unit->usec,
|
||||||
nb,
|
nb,
|
||||||
|
@ -188,16 +183,11 @@ void fsm_publish_log (struct fsm_log_t *gg_logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* LEAK SUMMARY:
|
* 2024-11-15 VALGRIND:
|
||||||
*
|
* LEAK SUMMARY:
|
||||||
* g_message (+) or printf
|
* definitely lost: 5,008 bytes in 54 blocks
|
||||||
* definitely lost: 5,008 bytes in 54 blocks
|
* indirectly lost: 16,151 bytes in 673 blocks
|
||||||
* indirectly lost: 16,151 bytes in 673 blocks
|
*/
|
||||||
*
|
|
||||||
* g_message (-)
|
|
||||||
* definitely lost: 5,776 bytes in 55 blocks
|
|
||||||
* indirectly lost: 17,703 bytes in 728 blocks
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
*/
|
*/
|
||||||
void on_toggle_exec_edit (GtkWidget *toggled_button, gpointer user_data)
|
void on_toggle_exec_edit (GtkWidget *toggled_button, gpointer user_data)
|
||||||
{
|
{
|
||||||
fsm_add_log (INFO, BUTTON, "signal", "toggle exec edit()",
|
fsm_add_log (INFO, BUTTON, "signal", __func__,
|
||||||
"flip status request + bell 😇️ gdk_display_beep()");
|
"flip status request + bell 😇️ gdk_display_beep()");
|
||||||
|
|
||||||
gdk_display_beep (gdk_display_get_default());
|
gdk_display_beep (gdk_display_get_default());
|
||||||
|
|
|
@ -83,7 +83,10 @@ void on_app_activation (GtkApplication *app)
|
||||||
|
|
||||||
g_signal_connect(window, "close-request", G_CALLBACK (on_window_close_request), (void *)(long long)window_int_id);
|
g_signal_connect(window, "close-request", G_CALLBACK (on_window_close_request), (void *)(long long)window_int_id);
|
||||||
|
|
||||||
char *temp = util_concat ("window_get_id = ", window_char_id, NULL);
|
int destination_string_size = 50 * sizeof(char);
|
||||||
|
char *temp = g_malloc0 (destination_string_size);
|
||||||
|
temp = strncat (temp, "window_get_id = ", destination_string_size);
|
||||||
|
temp = strncat (temp, window_char_id, destination_string_size);
|
||||||
fsm_add_log (INFO, WIDGETS, "widget/manager", __func__, temp);
|
fsm_add_log (INFO, WIDGETS, "widget/manager", __func__, temp);
|
||||||
free(temp);
|
free(temp);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue