log_manager.cc

Declared program_invocation_name, and program_invocation_short_name. They are used as identifier strings in syslog logging in cases where log_manager is not initialized explicitly and/or the caller hasn't specified program name as one of the arguments in arguments array.

	Fixed memory corruption. Length of sequence number of file name was calculated to as one too short and one byte was written to unallocated memory.

	Freed also the linkpath in cases where at least one of the log files is written to shm and a symlink is added to log directory.

mysql_client.c
	Added debug check for protocol pointer because of memory issues in mysql_client.c
This commit is contained in:
vraatikka 2013-11-13 22:08:10 +02:00
parent 1a3fa578da
commit 1c96824cb3
2 changed files with 23 additions and 5 deletions

View File

@ -37,6 +37,13 @@
#define MAX_PATHLEN 512
#define MAXNBLOCKBUFS 10
/** for procname */
#define _GNU_SOURCE
extern char *program_invocation_name;
extern char *program_invocation_short_name;
/**
* BUFSIZ comes from the system. It equals with block size or
* its multiplication.
@ -58,8 +65,10 @@ const char* shm_pathname = "/dev/shm";
/** Logfile ids from call argument '-s' */
char* shmem_id_str = NULL;
char* syslog_id_str = NULL;
/** Errors are written to syslog too by default */
char* syslog_id_str = strdup("LOGFILE_ERROR");
char* syslog_ident_str = NULL;
/**
* Global log manager pointer and lock variable.
* lmlock protects logmanager access.
@ -1402,6 +1411,10 @@ static bool fnames_conf_init(
case 'l':
/** record list of log file ids for syslogged */
if (syslog_id_str != NULL)
{
free (syslog_id_str);
}
syslog_id_str = optarg;
break;
@ -1446,8 +1459,11 @@ static bool fnames_conf_init(
strdup(get_logpath_default()) : fn->fn_logpath;
/** Set identity string for syslog if it is not set in config.*/
syslog_ident_str = (syslog_ident_str == NULL) ?
syslog_ident_str = strdup(*argv) : syslog_ident_str;
syslog_ident_str =
(syslog_ident_str == NULL ?
(argv == NULL ? strdup(program_invocation_short_name) :
strdup(*argv)) :
syslog_ident_str);
/* ss_dfprintf(stderr, "\n\n\tCommand line : ");
for (i=0; i<argc; i++) {
@ -1671,7 +1687,7 @@ static char* form_full_file_name(
if (seqno != -1)
{
s = UINTLEN(seqno);
seqnostr = (char *)malloc((int)s);
seqnostr = (char *)malloc((int)s+1);
}
else
{
@ -1807,7 +1823,7 @@ static bool file_exists(
{
*writable = true;
}
close(fd);
close(fd);
}
}
else
@ -2068,6 +2084,7 @@ static void logfile_free_memory(
logfile_t* lf)
{
if (lf->lf_filepath != NULL) free(lf->lf_filepath);
if (lf->lf_linkpath != NULL) free(lf->lf_linkpath);
if (lf->lf_name_prefix != NULL) free(lf->lf_name_prefix);
if (lf->lf_name_suffix != NULL) free(lf->lf_name_suffix);
if (lf->lf_full_link_name != NULL) free(lf->lf_full_link_name);

View File

@ -361,6 +361,7 @@ static int gw_mysql_do_authentication(DCB *dcb, GWBUF *queue) {
CHK_DCB(dcb);
protocol = DCB_PROTOCOL(dcb, MySQLProtocol);
CHK_PROTOCOL(protocol);
client_data = (MYSQL_session *)calloc(1, sizeof(MYSQL_session));
dcb->data = client_data;