axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sam...@apache.org
Subject cvs commit: ws-axis/c/src/common AxisConfig.cpp
Date Tue, 07 Sep 2004 05:43:23 GMT
samisa      2004/09/06 22:43:23

  Modified:    c/src/common AxisConfig.cpp
  Log:
  Fixed few memory leak problems with pointers stored in m_pcValueArray
  
  Revision  Changes    Path
  1.47      +226 -203  ws-axis/c/src/common/AxisConfig.cpp
  
  Index: AxisConfig.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/common/AxisConfig.cpp,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- AxisConfig.cpp	3 Sep 2004 14:45:11 -0000	1.46
  +++ AxisConfig.cpp	7 Sep 2004 05:43:23 -0000	1.47
  @@ -28,56 +28,63 @@
   #include <stdio.h>
   #include <string.h>
   
  -AXIS_CPP_NAMESPACE_START
  -
  -AxisConfig::AxisConfig ()
  +AXIS_CPP_NAMESPACE_START AxisConfig::AxisConfig ()
   {
       m_pcAxisHome = 0;
  -	m_pcKeyArray[AXCONF_WSDDFILEPATH] = "WSDDFilePath";
  -	m_pcKeyArray[AXCONF_LOGPATH] = "LogPath";
  -	m_pcKeyArray[AXCONF_CLIENTLOGPATH] = "ClientLogPath";
  -	m_pcKeyArray[AXCONF_CLIENTWSDDFILEPATH] = "ClientWSDDFilePath";
  -	/*
  -	The value for this is taken from the environment variable "AXISCPP_DEPLOY".
  -	So no need for a key for AXCONF_AXISHOME
  -	*/
  -	m_pcKeyArray[AXCONF_AXISHOME] = "\0";
  -	m_pcKeyArray[AXCONF_TRANSPORTHTTP]="Transport_http";
  -	m_pcKeyArray[AXCONF_TRANSPORTSMTP]="Transport_smtp";
  -	m_pcKeyArray[AXCONF_XMLPARSER] = "XMLParser";
  -	m_pcKeyArray[AXCONF_NODENAME] = "NodeName";
  -	m_pcKeyArray[AXCONF_LISTENPORT] = "ListenPort";
  +    m_pcKeyArray[AXCONF_WSDDFILEPATH] = "WSDDFilePath";
  +    m_pcKeyArray[AXCONF_LOGPATH] = "LogPath";
  +    m_pcKeyArray[AXCONF_CLIENTLOGPATH] = "ClientLogPath";
  +    m_pcKeyArray[AXCONF_CLIENTWSDDFILEPATH] = "ClientWSDDFilePath";
  +    /*
  +       The value for this is taken from the environment variable "AXISCPP_DEPLOY".
  +       So no need for a key for AXCONF_AXISHOME
  +     */
  +    m_pcKeyArray[AXCONF_AXISHOME] = "\0";
  +    m_pcKeyArray[AXCONF_TRANSPORTHTTP] = "Transport_http";
  +    m_pcKeyArray[AXCONF_TRANSPORTSMTP] = "Transport_smtp";
  +    m_pcKeyArray[AXCONF_XMLPARSER] = "XMLParser";
  +    m_pcKeyArray[AXCONF_NODENAME] = "NodeName";
  +    m_pcKeyArray[AXCONF_LISTENPORT] = "ListenPort";
   
  -    for(int i=0;i<AXCONF_LAST;i++)
  -	{
  -        m_pcValueArray[i] = NULL; 
  -	}
  +    for (int i = 0; i < AXCONF_LAST; i++)
  +    {
  +	m_pcValueArray[i] = NULL;
  +    }
   
   #ifdef _DEBUG
   #ifdef WIN32
  -	m_pcValueArray[AXCONF_XMLPARSER] = "AxisXMLParser_D.dll";
  -	m_pcValueArray[AXCONF_TRANSPORTHTTP] = "AxisTransport_D.dll";
  -    m_pcValueArray[AXCONF_NODENAME] = "server name";
  -    m_pcValueArray[AXCONF_LISTENPORT] = "listen port";
  +    // Samisa : I used strdup here so that I could use free in destructor
  +    // This was done to make sure that the memory allocated in AxisConfig::setValue
  +    // is freed properly
  +    m_pcValueArray[AXCONF_XMLPARSER] = strdup ("AxisXMLParser_D.dll");
  +    m_pcValueArray[AXCONF_TRANSPORTHTTP] = strdup ("AxisTransport_D.dll");
  +    m_pcValueArray[AXCONF_NODENAME] = strdup ("server name");
  +    m_pcValueArray[AXCONF_LISTENPORT] = strdup ("listen port");
   #else
  -	m_pcValueArray[AXCONF_XMLPARSER] = "/usr/local/Axis/libs/libaxis_xmlparser.so";
  -	m_pcValueArray[AXCONF_TRANSPORTHTTP] = "/usr/local/Axis/libs/libaxis_transport.so";
  -    m_pcValueArray[AXCONF_NODENAME] = "server name";
  -    m_pcValueArray[AXCONF_LISTENPORT] = "listen port";
  +    m_pcValueArray[AXCONF_XMLPARSER] =
  +	strdup ("/usr/local/Axis/libs/libaxis_xmlparser.so");
  +    m_pcValueArray[AXCONF_TRANSPORTHTTP] =
  +	strdup ("/usr/local/Axis/libs/libaxis_transport.so");
  +    m_pcValueArray[AXCONF_NODENAME] = strdup ("server name");
  +    m_pcValueArray[AXCONF_LISTENPORT] = strdup ("listen port");
   #endif
   #else
   #ifdef WIN32
  -    m_pcValueArray[AXCONF_XMLPARSER] = "AxisXMLParser.dll";
  -	m_pcValueArray[AXCONF_TRANSPORTHTTP] = "AxisTransport.dll";
  -    m_pcValueArray[AXCONF_NODENAME] = "server name";
  -    m_pcValueArray[AXCONF_LISTENPORT] = "listen port";
  +    m_pcValueArray[AXCONF_XMLPARSER] = strdup ("AxisXMLParser.dll");
  +    m_pcValueArray[AXCONF_TRANSPORTHTTP] = strdup ("AxisTransport.dll");
  +    m_pcValueArray[AXCONF_NODENAME] = strdup ("server name");
  +    m_pcValueArray[AXCONF_LISTENPORT] = strdup ("listen port");
   #else
  -	m_pcValueArray[AXCONF_XMLPARSER] = "/usr/local/axiscpp_deploy/lib/libaxis_xmlparser.so";
  -	m_pcValueArray[AXCONF_TRANSPORTHTTP] = "/usr/local/axiscpp_deploy/lib/libaxis_transport.so";
  -    m_pcValueArray[AXCONF_LOGPATH] = "/usr/local/axiscpp_deploy/log/AxisLog";
  -    m_pcValueArray[AXCONF_CLIENTLOGPATH] = "/usr/local/axiscpp_deploy/log/AxisClientLog";
  -    m_pcValueArray[AXCONF_NODENAME] = "server name";
  -    m_pcValueArray[AXCONF_LISTENPORT] = "listen port";
  +    m_pcValueArray[AXCONF_XMLPARSER] =
  +	strdup ("/usr/local/axiscpp_deploy/lib/libaxis_xmlparser.so");
  +    m_pcValueArray[AXCONF_TRANSPORTHTTP] =
  +	strdup ("/usr/local/axiscpp_deploy/lib/libaxis_transport.so");
  +    m_pcValueArray[AXCONF_LOGPATH] =
  +	strdup ("/usr/local/axiscpp_deploy/log/AxisLog");
  +    m_pcValueArray[AXCONF_CLIENTLOGPATH] =
  +	strdup ("/usr/local/axiscpp_deploy/log/AxisClientLog");
  +    m_pcValueArray[AXCONF_NODENAME] = strdup ("server name");
  +    m_pcValueArray[AXCONF_LISTENPORT] = strdup ("listen port");
   #endif
   #endif
   
  @@ -85,32 +92,38 @@
   
   AxisConfig::~AxisConfig ()
   {
  +    for (int i = 0; i < AXCONF_LAST; i++)
  +    {
  +	m_pcValueArray[i] = NULL;
  +    }
  +
   }
   
  -int AxisConfig::readConfFile ()
  +int
  +AxisConfig::readConfFile ()
   {
       char carrLine[CONFBUFFSIZE];
  -    char* pcValue;
  -    AxisFile fileConfig; /*AxisFile is AxisC++ resource for file manipulation */
  -    char* sConfPath = NULL;
  -    char* sNewConfPath = (char*) malloc(CONFBUFFSIZE);
  -    char* key;
  -	int iValueLength = 0;
  -	const char* pcSeparator = ":";
  -	const char pcComment = '#';
  +    char *pcValue;
  +    AxisFile fileConfig;	/*AxisFile is AxisC++ resource for file manipulation */
  +    char *sConfPath = NULL;
  +    char *sNewConfPath = (char *) malloc (CONFBUFFSIZE);
  +    char *key;
  +    int iValueLength = 0;
  +    const char *pcSeparator = ":";
  +    const char pcComment = '#';
   
       sConfPath = getenv ("AXISCPP_DEPLOY");
  -	m_pcValueArray[AXCONF_AXISHOME] = sConfPath;
  -	/*
  -	Even if the AXISCPP_DEPLOY environment variable is not set default values 
  -	will be used. Therefore return AXIS_SUCCESS
  -	*/
  -    if (!sConfPath || (sConfPath == '\0') ) 
  +    m_pcValueArray[AXCONF_AXISHOME] = sConfPath;
  +    /*
  +       Even if the AXISCPP_DEPLOY environment variable is not set default values 
  +       will be used. Therefore return AXIS_SUCCESS
  +     */
  +    if (!sConfPath || (sConfPath == '\0'))
       {
  -        free(sNewConfPath);
  -        return AXIS_SUCCESS;
  +	free (sNewConfPath);
  +	return AXIS_SUCCESS;
       }
  -    m_pcAxisHome = (char*) malloc (CONFBUFFSIZE);
  +    m_pcAxisHome = (char *) malloc (CONFBUFFSIZE);
       strcpy (m_pcAxisHome, sConfPath);
   
       strcpy (sNewConfPath, sConfPath);
  @@ -119,100 +132,108 @@
   #else
       strcat (sNewConfPath, "/etc/axiscpp.conf");
   #endif
  -	/*
  -	Even if axiscpp.conf does not exist in AXISCPP_DEPLOY default values 
  -	will be used. Therefore return AXIS_SUCCESS
  -	*/
  -    if (AXIS_SUCCESS != fileConfig.fileOpen(sNewConfPath, "r"))
  +    /*
  +       Even if axiscpp.conf does not exist in AXISCPP_DEPLOY default values 
  +       will be used. Therefore return AXIS_SUCCESS
  +     */
  +    if (AXIS_SUCCESS != fileConfig.fileOpen (sNewConfPath, "r"))
       {
  -        free(sNewConfPath);
  +	free (sNewConfPath);
   
   #ifdef _DEBUG
  -		printf( "Warning - The configuration file was not found (%s).\n          Using the following
default file paths.\n", sNewConfPath);
  +	printf
  +	    ("Warning - The configuration file was not found (%s).\n          Using the following
default file paths.\n",
  +	     sNewConfPath);
   
  -		OutputConfigInfo();
  +	OutputConfigInfo ();
   #else
  -		printf( "Warning - The configuration file was not found (%s).\n", sNewConfPath);
  +	printf ("Warning - The configuration file was not found (%s).\n",
  +		sNewConfPath);
   #endif
  -        return AXIS_SUCCESS;
  +	return AXIS_SUCCESS;
       }
   
  -    while (AXIS_SUCCESS == fileConfig.fileGet(carrLine, CONFBUFFSIZE)) 
  +    while (AXIS_SUCCESS == fileConfig.fileGet (carrLine, CONFBUFFSIZE))
       {
  -        int linesize = strlen (carrLine);
  -		/*
  -		Ignore lines starting with # and empty lines
  -		*/
  -		if(carrLine[0]== pcComment || carrLine[0]=='\0')
  -			continue;
  -        pcValue = strpbrk (carrLine, pcSeparator);
  -        if (!pcValue)
  -            break;
  -        key = (char*) malloc (pcValue - carrLine + 1);
  -        pcValue[0] = '\0';
  -        sscanf (carrLine, "%s", key);
  -		iValueLength = linesize - strlen (key) - 1;
  -
  -		bool bKeyFound = false;
  -
  -        for(int i=0;i<AXCONF_LAST;i++)
  -		{
  -			if(strcmp(key, m_pcKeyArray[i]) == 0)
  -			{
  -				setValue(iValueLength, (g_axconfig)i, pcValue+1);
  +	int linesize = strlen (carrLine);
  +	/*
  +	   Ignore lines starting with # and empty lines
  +	 */
  +	if (carrLine[0] == pcComment || carrLine[0] == '\0')
  +	    continue;
  +	pcValue = strpbrk (carrLine, pcSeparator);
  +	if (!pcValue)
  +	    break;
  +	key = (char *) malloc (pcValue - carrLine + 1);
  +	pcValue[0] = '\0';
  +	sscanf (carrLine, "%s", key);
  +	iValueLength = linesize - strlen (key) - 1;
  +
  +	bool bKeyFound = false;
  +
  +	for (int i = 0; i < AXCONF_LAST; i++)
  +	{
  +	    if (strcmp (key, m_pcKeyArray[i]) == 0)
  +	    {
  +		setValue (iValueLength, (g_axconfig) i, pcValue + 1);
   
   // If the name/value pair is a reference to a WSDD file, then the file must exist.
   // If the WSDD file does not exist, then echo a warning to the console.
  -				if( strcmp( "WSDDFilePath", key) == NULL ||
  -				    strcmp( "ClientWSDDFilePath", key) == NULL)
  -				{
  -					FILE *	fp = fopen( pcValue + 1, "r");
  -
  -					if( fp == NULL)
  -					{
  -						printf( "Warning - The %s file (%s) in the AXISCPP.CONF file does not exist.\n",
key, pcValue + 1);
  -					}
  -					else
  -					{
  -						fclose( fp);
  -					}
  -				}
  -
  -				bKeyFound = true;
  -				break;
  -			}
  -		}
  -
  -		if( !bKeyFound)
  +		if (strcmp ("WSDDFilePath", key) == NULL ||
  +		    strcmp ("ClientWSDDFilePath", key) == NULL)
   		{
  -			printf( "Warning - Unknown key (%s) in config file.\n", key);
  +		    FILE *fp = fopen (pcValue + 1, "r");
  +
  +		    if (fp == NULL)
  +		    {
  +			printf
  +			    ("Warning - The %s file (%s) in the AXISCPP.CONF file does not exist.\n",
  +			     key, pcValue + 1);
  +		    }
  +		    else
  +		    {
  +			fclose (fp);
  +		    }
   		}
   
  -		free(key);
  +		bKeyFound = true;
  +		break;
  +	    }
  +	}
  +
  +	if (!bKeyFound)
  +	{
  +	    printf ("Warning - Unknown key (%s) in config file.\n", key);
  +	}
  +
  +	free (key);
       }
   
  -    free(sNewConfPath);
  +    free (sNewConfPath);
   
   #ifdef _DEBUG
  -	printf( "The AXIS configuration has now been set to:-\n");
  +    printf ("The AXIS configuration has now been set to:-\n");
   
  -	OutputConfigInfo();
  +    OutputConfigInfo ();
   #endif
       return AXIS_SUCCESS;
   }
   
  -void AxisConfig::setValue(int valuelength, g_axconfig valueindex, char* value)
  +void
  +AxisConfig::setValue (int valuelength, g_axconfig valueindex, char *value)
   {
  -    m_pcValueArray[valueindex] =  (char*) malloc (valuelength+1);
  -    strncpy (m_pcValueArray[valueindex], value, valuelength+1);
  -	//*(m_pcValueArray[valueindex]+valuelength)
  -        //= '\0';
  +    // erase memory allocated for default value
  +    if (m_pcValueArray[valueindex])
  +        free (m_pcValueArray[valueindex]);
  +    m_pcValueArray[valueindex] = (char *) malloc (valuelength + 1);
  +    strncpy (m_pcValueArray[valueindex], value, valuelength + 1);
   }
   
   
  -char* AxisConfig::getAxisConfProperty(g_axconfig property)
  +char *
  +AxisConfig::getAxisConfProperty (g_axconfig property)
   {
  -	return m_pcValueArray[property];
  +    return m_pcValueArray[property];
   }
   
   
  @@ -231,88 +252,90 @@
   
   */
   
  -void AxisConfig::OutputConfigInfo()
  +void
  +AxisConfig::OutputConfigInfo ()
   {
  -	if( m_pcValueArray[AXCONF_WSDDFILEPATH] == NULL)
  -	{
  -		printf( "WSDD           (null)\n");
  -	}
  -	else
  -	{
  -		printf( "WSDD           %s\n", m_pcValueArray[AXCONF_WSDDFILEPATH]);
  -	}
  -	if( m_pcValueArray[AXCONF_LOGPATH] == NULL)
  -	{
  -		printf( "Log            (null)\n");
  -	}
  -	else
  -	{
  -		printf( "Log            %s\n", m_pcValueArray[AXCONF_LOGPATH]);
  -	}
  -	if( m_pcValueArray[AXCONF_CLIENTLOGPATH] == NULL)
  -	{
  -		printf( "Client Log     (null)\n");
  -	}
  -	else
  -	{
  -		printf( "Client Log     %s\n", m_pcValueArray[AXCONF_CLIENTLOGPATH]);
  -	}
  -	if( m_pcValueArray[AXCONF_CLIENTWSDDFILEPATH] == NULL)
  -	{
  -		printf( "ClientWSDD     (null)\n");
  -	}
  -	else
  -	{
  -		printf( "ClientWSDD     %s\n", m_pcValueArray[AXCONF_CLIENTWSDDFILEPATH]);
  -	}
  -	if( m_pcValueArray[AXCONF_AXISHOME] == NULL)
  -	{
  -		printf( "AXIS HOME      (null)\n");
  -	}
  -	else
  -	{
  -		printf( "AXIS HOME      %s\n", m_pcValueArray[AXCONF_AXISHOME]);
  -	}
  -	if( m_pcValueArray[AXCONF_TRANSPORTHTTP] == NULL)
  -	{
  -		printf( "Transport HTTP (null)\n");
  -	}
  -	else
  -	{
  -		printf( "Transport HTTP %s\n", m_pcValueArray[AXCONF_TRANSPORTHTTP]);
  -	}
  -	if( m_pcValueArray[AXCONF_TRANSPORTSMTP] == NULL)
  -	{
  -		printf( "Transport SMTP (null)\n");
  -	}
  -	else
  -	{
  -		printf( "Transport SMTP %s\n", m_pcValueArray[AXCONF_TRANSPORTSMTP]);
  -	}
  -	if( m_pcValueArray[AXCONF_XMLPARSER] == NULL)
  -	{
  -		printf( "XML Parser     (null)\n");
  -	}
  -	else
  -	{
  -		printf( "XML Parser     %s\n", m_pcValueArray[AXCONF_XMLPARSER]);
  -	}
  -	if( m_pcValueArray[AXCONF_NODENAME] == NULL)
  -	{
  -		printf( "Node Name      (null)\n");
  -	}
  -	else
  -	{
  -		printf( "Node Name      %s\n", m_pcValueArray[AXCONF_NODENAME]);
  -	}
  -	if( m_pcValueArray[AXCONF_LISTENPORT] == NULL)
  -	{
  -		printf( "Listen Port    (null)\n");
  -	}
  -	else
  -	{
  -		printf( "Listen Port    %s\n", m_pcValueArray[AXCONF_LISTENPORT]);
  -	}
  +    if (m_pcValueArray[AXCONF_WSDDFILEPATH] == NULL)
  +    {
  +	printf ("WSDD           (null)\n");
  +    }
  +    else
  +    {
  +	printf ("WSDD           %s\n", m_pcValueArray[AXCONF_WSDDFILEPATH]);
  +    }
  +    if (m_pcValueArray[AXCONF_LOGPATH] == NULL)
  +    {
  +	printf ("Log            (null)\n");
  +    }
  +    else
  +    {
  +	printf ("Log            %s\n", m_pcValueArray[AXCONF_LOGPATH]);
  +    }
  +    if (m_pcValueArray[AXCONF_CLIENTLOGPATH] == NULL)
  +    {
  +	printf ("Client Log     (null)\n");
  +    }
  +    else
  +    {
  +	printf ("Client Log     %s\n", m_pcValueArray[AXCONF_CLIENTLOGPATH]);
  +    }
  +    if (m_pcValueArray[AXCONF_CLIENTWSDDFILEPATH] == NULL)
  +    {
  +	printf ("ClientWSDD     (null)\n");
  +    }
  +    else
  +    {
  +	printf ("ClientWSDD     %s\n",
  +		m_pcValueArray[AXCONF_CLIENTWSDDFILEPATH]);
  +    }
  +    if (m_pcValueArray[AXCONF_AXISHOME] == NULL)
  +    {
  +	printf ("AXIS HOME      (null)\n");
  +    }
  +    else
  +    {
  +	printf ("AXIS HOME      %s\n", m_pcValueArray[AXCONF_AXISHOME]);
  +    }
  +    if (m_pcValueArray[AXCONF_TRANSPORTHTTP] == NULL)
  +    {
  +	printf ("Transport HTTP (null)\n");
  +    }
  +    else
  +    {
  +	printf ("Transport HTTP %s\n", m_pcValueArray[AXCONF_TRANSPORTHTTP]);
  +    }
  +    if (m_pcValueArray[AXCONF_TRANSPORTSMTP] == NULL)
  +    {
  +	printf ("Transport SMTP (null)\n");
  +    }
  +    else
  +    {
  +	printf ("Transport SMTP %s\n", m_pcValueArray[AXCONF_TRANSPORTSMTP]);
  +    }
  +    if (m_pcValueArray[AXCONF_XMLPARSER] == NULL)
  +    {
  +	printf ("XML Parser     (null)\n");
  +    }
  +    else
  +    {
  +	printf ("XML Parser     %s\n", m_pcValueArray[AXCONF_XMLPARSER]);
  +    }
  +    if (m_pcValueArray[AXCONF_NODENAME] == NULL)
  +    {
  +	printf ("Node Name      (null)\n");
  +    }
  +    else
  +    {
  +	printf ("Node Name      %s\n", m_pcValueArray[AXCONF_NODENAME]);
  +    }
  +    if (m_pcValueArray[AXCONF_LISTENPORT] == NULL)
  +    {
  +	printf ("Listen Port    (null)\n");
  +    }
  +    else
  +    {
  +	printf ("Listen Port    %s\n", m_pcValueArray[AXCONF_LISTENPORT]);
  +    }
   }
   
   AXIS_CPP_NAMESPACE_END
  
  
  

Mime
View raw message