A
Anuradha
Below is the code which was written VC++ 6.0 under windows environment.
Executing the same throws:
------------------
Debug Error!
Program: ccheck.exe
DAMAGE: after normal block (#41) at 0x00300160
(Press Retry to debug the application)
------------------
While the free () statement is commented the program does not report the error.
Please do let me know your views ...
Thanks in advance.
# include <string.h>
# include <stdio.h>
# include <stdlib.h>
# include <errno.h>
# define _DEBUG_ 1
void SetProgramName (char *);
char * GetProgramName ();
void PrintUsage ();
void PrintErrMsg (size_t);
void ClearMemory ();
char *ProgramName = NULL;
extern errno;
int
main (int argc, char *argv[])
{
SetProgramName (argv[0]);
if (argc < 2)
{
PrintUsage ();
ClearMemory ();
}
return (EXIT_SUCCESS);
}
void
SetProgramName (char *PrgName)
{
ProgramName = (char *) malloc (strlen (PrgName));
if (ProgramName == NULL)
{
PrintErrMsg (errno);
}
else
{
(void) strcpy (ProgramName, PrgName);
#if defined (_DEBUG_)
(void) fprintf (stderr, "\n Debug: ProgramName %s \n", ProgramName);
#endif
}
}
char *
GetProgramName ()
{
return (ProgramName == NULL ? NULL : ProgramName);
}
void
ClearMemory ()
{
if (strlen (ProgramName) > 0)
{
free (ProgramName);
#if 0
ProgramName = NULL;
#endif
PrintErrMsg (errno);
}
}
void
PrintErrMsg (size_t ErrNumber)
{
(void) fprintf ( stderr, \
"\n Err Number [%ld] \n Err Msg [%s] \n", \
ErrNumber, strerror (ErrNumber)
);
}
void
PrintUsage ()
{
(void) fprintf (stderr, "\n %s <> <>", GetProgramName());
}
Executing the same throws:
------------------
Debug Error!
Program: ccheck.exe
DAMAGE: after normal block (#41) at 0x00300160
(Press Retry to debug the application)
------------------
While the free () statement is commented the program does not report the error.
Please do let me know your views ...
Thanks in advance.
# include <string.h>
# include <stdio.h>
# include <stdlib.h>
# include <errno.h>
# define _DEBUG_ 1
void SetProgramName (char *);
char * GetProgramName ();
void PrintUsage ();
void PrintErrMsg (size_t);
void ClearMemory ();
char *ProgramName = NULL;
extern errno;
int
main (int argc, char *argv[])
{
SetProgramName (argv[0]);
if (argc < 2)
{
PrintUsage ();
ClearMemory ();
}
return (EXIT_SUCCESS);
}
void
SetProgramName (char *PrgName)
{
ProgramName = (char *) malloc (strlen (PrgName));
if (ProgramName == NULL)
{
PrintErrMsg (errno);
}
else
{
(void) strcpy (ProgramName, PrgName);
#if defined (_DEBUG_)
(void) fprintf (stderr, "\n Debug: ProgramName %s \n", ProgramName);
#endif
}
}
char *
GetProgramName ()
{
return (ProgramName == NULL ? NULL : ProgramName);
}
void
ClearMemory ()
{
if (strlen (ProgramName) > 0)
{
free (ProgramName);
#if 0
ProgramName = NULL;
#endif
PrintErrMsg (errno);
}
}
void
PrintErrMsg (size_t ErrNumber)
{
(void) fprintf ( stderr, \
"\n Err Number [%ld] \n Err Msg [%s] \n", \
ErrNumber, strerror (ErrNumber)
);
}
void
PrintUsage ()
{
(void) fprintf (stderr, "\n %s <> <>", GetProgramName());
}