profiling: fix memory error in case of rule reload.

pull/71/merge
Victor Julien 13 years ago
parent ec7e79c748
commit 2343ff8950

@ -38,7 +38,7 @@ __thread int record_locks = 0;
int profiling_locks_enabled = 0;
int profiling_locks_output_to_file = 0;
char *profiling_locks_file_name = NULL;
char *profiling_locks_file_mode = NULL;
char *profiling_locks_file_mode = "a";
typedef struct LockRecord_ {
char *file; // hash
@ -147,11 +147,7 @@ void SCProfilingListLocks(void) {
FILE *fp = NULL;
if (profiling_locks_output_to_file == 1) {
if (strcasecmp(profiling_locks_file_mode, "yes") == 0) {
fp = fopen(profiling_locks_file_name, "a");
} else {
fp = fopen(profiling_locks_file_name, "w");
}
fp = fopen(profiling_locks_file_name, profiling_locks_file_mode);
if (fp == NULL) {
SCLogError(SC_ERR_FOPEN, "failed to open %s: %s",

@ -87,7 +87,7 @@ static SCProfileData rules_profile_data[0xffff];
static pthread_mutex_t rules_profile_data_m;
int profiling_rules_enabled = 0;
static char *profiling_file_name = "";
static const char *profiling_file_mode = "";
static const char *profiling_file_mode = "a";
/**
* Sort orders for dumping profiled rules.
@ -173,9 +173,12 @@ void SCProfilingRulesGlobalInit(void) {
profiling_file_name = SCMalloc(PATH_MAX);
snprintf(profiling_file_name, PATH_MAX, "%s/%s", log_dir, filename);
profiling_file_mode = ConfNodeLookupChildValue(conf, "append");
if (profiling_file_mode == NULL)
profiling_file_mode = DEFAULT_LOG_MODE_APPEND;
const char *v = ConfNodeLookupChildValue(conf, "append");
if (v == NULL || ConfValIsTrue(v)) {
profiling_file_mode = "a";
} else {
profiling_file_mode = "w";
}
profiling_output_to_file = 1;
}
@ -272,11 +275,7 @@ SCProfilingRuleDump(SCProfileDetectCtx *rules_ctx)
struct timeval tval;
struct tm *tms;
if (profiling_output_to_file == 1) {
if (ConfValIsTrue(profiling_file_mode)) {
fp = fopen(profiling_file_name, "a");
} else {
fp = fopen(profiling_file_name, "w");
}
fp = fopen(profiling_file_name, profiling_file_mode);
if (fp == NULL) {
SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", profiling_file_name,

@ -94,7 +94,7 @@ int profiling_packets_output_to_file = 0;
char *profiling_file_name;
char *profiling_packets_file_name;
char *profiling_csv_file_name;
const char *profiling_packets_file_mode;
const char *profiling_packets_file_mode = "a";
/**
* Used as a check so we don't double enter a profiling run.
@ -143,9 +143,12 @@ SCProfilingInit(void)
profiling_packets_file_name = SCMalloc(PATH_MAX);
snprintf(profiling_packets_file_name, PATH_MAX, "%s/%s", log_dir, filename);
profiling_packets_file_mode = ConfNodeLookupChildValue(conf, "append");
if (profiling_packets_file_mode == NULL)
profiling_packets_file_mode = DEFAULT_LOG_MODE_APPEND;
const char *v = ConfNodeLookupChildValue(conf, "append");
if (v == NULL || ConfValIsTrue(v)) {
profiling_packets_file_mode = "a";
} else {
profiling_packets_file_mode = "w";
}
profiling_packets_output_to_file = 1;
}
@ -214,9 +217,12 @@ SCProfilingInit(void)
profiling_locks_file_name = SCMalloc(PATH_MAX);
snprintf(profiling_locks_file_name, PATH_MAX, "%s/%s", log_dir, filename);
profiling_locks_file_mode = (char *)ConfNodeLookupChildValue(conf, "append");
if (profiling_locks_file_mode == NULL)
profiling_locks_file_mode = DEFAULT_LOG_MODE_APPEND;
const char *v = ConfNodeLookupChildValue(conf, "append");
if (v == NULL || ConfValIsTrue(v)) {
profiling_locks_file_mode = "a";
} else {
profiling_locks_file_mode = "w";
}
profiling_locks_output_to_file = 1;
}
@ -267,11 +273,7 @@ void SCProfilingDumpPacketStats(void) {
return;
if (profiling_packets_output_to_file == 1) {
if (strcasecmp(profiling_packets_file_mode, "yes") == 0) {
fp = fopen(profiling_packets_file_name, "a");
} else {
fp = fopen(profiling_packets_file_name, "w");
}
fp = fopen(profiling_packets_file_name, profiling_packets_file_mode);
if (fp == NULL) {
SCLogError(SC_ERR_FOPEN, "failed to open %s: %s",

Loading…
Cancel
Save