Termination of Application developed in QNX4.25 with photon

APPLICATION for Process Industry: 60 T Eccentric Bottom taping ELECTRIC ARC FURNACE

Process Computer Configuration:

(1)Hardware Configuration: PIII, 750 MHZ .128 MB RAM.
(2)Software Configuration: Operating system - QNX 4.25
GUI – Photon Runtime and Application Builder
Compiler- Watcom C
Application was developed for
(a)Monitoring the process parameter such as temperature, pressure, flow rate.
(b)Control of set point for feeding raw material inside the furnace.
(c)Generation of events on receiving interrupts.
(d)Trend logging of various process parameter

Problem Occurred: Our developed application is running as per logic. During running of project,application terminates with error- memory fault after gap period of Days or some times with a gap period of Hours.

Our Observation: The cause of problem may be one

of the following.

(1)There was a generation multiple text boxes for recording of time in text box using a code on receiving Process interrupts. After editing of records, application terminates with error memory fault after gap Period of Days or some times with a gap period of Hours.

Memory was allocated to the struct SHDATA using malloc
and it is free using free(malloc).

After making such correction , termination of application has been reduced up to some extent but still problem is there.

Pl. share us your views on the above problem and following queries

(2)In our application the code associated with base window is in setup.c.

The shared memory is open with coding
fd = shm_open("Shared_Mem,O_RDWR | O_CBEAT,0777);
ltrunc(fd,SIZE+1,seek_SET);

The memory is mapped using
sh = (unsigned int ) mmap (0,sizeof(struct SHDATA),PROT_READ
|PROT_WRITE,MAP_SHARED | MAP_FIXED ,fd,0)

This code is executed at the start of application only. The shared memory is used by struct SHDATA in other part of application ,which is activated on the occurrence of events.This memory is not deallocated
at any point of programmed.Is it required to deallocate this memory with
pgshmemCleanup() or pgshmemDeattach() function ?.

(2) Are shared variable utilized cummulative memory, whenever the code is executed ?

(3) Do you found any bug in real time appllication using photon?

Can any body share his views on above problem . The code is attached herewith.

/* Y o u r D e s c r i p t i o n /
/
AppBuilder Photon Code Lib - Version 1.14C */

/* Standard headers /
#include “standard.h”
#include <math.h>
/
Toolkit headers */
#include <Ph.h>
#include <Pt.h>
#include <Ap.h>

/* Local headers */
#include “shd.h”
#include “abimport.h”
#include “proto.h”
#include “shdext.h”

struct INTERRUPTION TempDelay[MAXINT];

int x2=5, y2=5,p2=0,q2=0,j=0,k=0,ic=0,norecords=0;
PhPoint_t Pos_d;
PhArea_t Area_d;
PhDim_t Dim_d={20,20};
PhDim_t Dim_d1={180,20};
PhDim_t Dim_d2={54,20};
PhDim_t Dim_d3={47,20};
PhDim_t Dim_d4={38,20};
PhPoint_t Post= {200, 100};
PtFileSelectionInfo_t FName;
unsigned char bpastDelayFlg=FALSE,bMornRepFlg=FALSE;
extern int verify_uppernum( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo );
char ShowHeat[8];
char filenameI[25];
long filesize();
unsigned char Onc=FALSE,bPastInt=FALSE,bGetHeatFlg=FALSE;

PtWidget_t *Group_I[120],*Group_C[120],*Text[5][120];

int
read_code( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{
PtArg_t args[2];
int res=0,res1=0;
char *strcode;

/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

s=(struct SHDATA *)MK_FP(sh,0);



s=0;

if(j==0 && !Onc)
{
	setlocale(LC_ALL,"C");
	PtSetArg(&args[0],Pt_ARG_TEXT_STRING,&strcode, 0);
	PtGetResources(Text[4][k],1,args);
	if(bPastInt)
		strxfrm(TempDelay[k].sDelayCode,strcode,4);
	else
		strxfrm(s->Intst[k].sDelayCode,strcode,4);
	++k;
	Onc=TRUE;
}

if(j >0)
{
	res=(int)(j%j);
	res1=(int)(j/j);	
}


if(res==0 && res1==1)
{
	if(ic==0)
	{
		setlocale(LC_ALL,"C");
		PtSetArg(&args[0],Pt_ARG_TEXT_STRING,&strcode, 0);
		PtGetResources(Text[4][k],1,args);
		if(bPastInt)
			strxfrm(TempDelay[k].sDelayCode,strcode,4);
		else
			strxfrm(s->Intst[k].sDelayCode,strcode,4);
		++k;
	}
	++ic;
	if(ic==2)
		ic=0;
}


if(cbinfo->reason_subtype == Pt_EDIT_ACTIVATE)
{	
	++q2;

	if(q2 <=2)
		j=q2-1;
	else 
	{
		if(j <= 3 )	j=q2-2;	
		else if(j <= 4 || j <=  5)	j=q2-3;
		else if(j <= 6 || j <=  7)	j=q2-4;
		else if(j <= 8 || j <=  9)	j=q2-5;
		else if(j <=10 || j <= 11)	j=q2-6;
		else if(j <=12 || j <= 13)	j=q2-7;
		else if(j <=14 || j <= 15)	j=q2-8;
		else if(j <=16 || j <= 17)	j=q2-9;
		else if(j <=18 || j <= 19)	j=q2-10;
		else if(j <=20 || j <= 21)	j=q2-11;
		else if(j <=22 || j <= 23)	j=q2-12;
		else if(j <=24 || j <= 25)	j=q2-13;
		else if(j <=26 || j <= 27)	j=q2-14;
		else if(j <=28 || j <= 29) j=q2-15;
		else if(j <=30 || j <= 31)	j=q2-16;
		else if(j <=32 || j <= 33)j=q2-17;
	}
	if(j <p2)
	{

		PtContainerGiveFocus(Text[4][j],NULL);
		j=q2-1;
	}
	else
	{
		q2=0;
		j=0;
		ic=0;
		k=0;
		Onc=FALSE;

	}
}

return( Pt_CONTINUE );

}

// The following code is called in ‘Current Interruption Dialog Box’ when “Relized” event of “PtScrollArea” is get activated.
int
Inter_Heat( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )
{

PtArg_t		args[10];
int			nargs,i;
char		*str;
char		buff[10];	


/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

str=(char *)(malloc(sizeof(char)));
s=(struct SHDATA *)MK_FP(sh,0);
s=0;

x2=5;	y2=5;

for(i=0;i<s->iNoOfInts;i++)
{

	
		PtSetParentWidget(ABW_IntList);
		Pos_d.x = x2;
		Pos_d.y = y2;

		PtSetArg( &args[0], Pt_ARG_POS, &Pos_d, 0 );
		Group_I[p2] = PtCreateWidget( PtGroup, NULL, 1, &args );    


		s->Intst[i].iSerNo=i+1;
		itoa(s->Intst[i].iSerNo,buff,10);

		nargs=0;
		Area_d.pos.y = 15;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 2, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,buff , 0);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d, 0);
		Text[0][p2] = PtCreateWidget( PtLabel,Group_I[p2],nargs, &args );    
	

		nargs=0;
		Area_d.pos.y = 15;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 14, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,s->Intst[i].sIntEvent,0);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d1, 0);
		Text[1][p2] = PtCreateWidget( PtText, Group_I[p2], nargs, &args );    


		str=(char *)(ctime(&s->Intst[i].lIntStartTime)+11);
		*(str+8)=0x00;

		nargs=0;
		Area_d.pos.y = 15;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 8, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,str , 0);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d2, 0);
		Text[2][p2] = PtCreateWidget( PtText, Group_I[p2], nargs, &args );    

		str=(char *)(ctime(&s->Intst[i].lIntStopTime)+11);
		*(str+8)=0x00;

		nargs=0;
		Area_d.pos.y = 15;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 8, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_FLAGS,Pt_EDITABLE,Pt_FALSE );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,str , 0);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d2, 0);
		Text[3][p2] = PtCreateWidget( PtText, Group_I[p2], nargs, &args );    


		Pos_d.x = x2+400;
		Pos_d.y = y2;
		nargs=0;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 4, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,s->Intst[i].sDelayCode, 0);
		PtSetArg(&args[nargs++], Pt_ARG_FLAGS,Pt_SET | Pt_HIGHLIGHTED | Pt_GETS_FOCUS | Pt_FOCUS_RENDER,Pt_SET | Pt_HIGHLIGHTED | Pt_GETS_FOCUS | Pt_FOCUS_RENDER);
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_FLAGS,Pt_CURSOR_VISIBLE | Pt_TEXT_AUTO_HIGHLIGHT | Pt_EDITABLE | Pt_INSERT_MODE,Pt_CURSOR_VISIBLE | Pt_TEXT_AUTO_HIGHLIGHT | Pt_EDITABLE | Pt_INSERT_MODE);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d3, 0);
		Text[4][p2] = PtCreateWidget( PtText, Group_I[p2], nargs, &args );  
		PtAddCallback(Text[4][p2], Pt_CB_REALIZED, &verify_uppernum, NULL);
		PtAddCallback(Text[4][p2], Pt_CB_ACTIVATE, &read_code, NULL);			

		PtRealizeWidget(Group_I[p2]);
		y2 = y2 + 21 ;				
		++p2;

	}
		PtContainerGiveFocus(Text[4][0],NULL);


free(str);
return( Pt_CONTINUE );

}

// The following code is called in ‘Past Delay Dialog Box’ when “Relized” event of “PtScrollArea” is get activated.
int
past_inttrupt( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )

{

PtArg_t		args[10];
char		*str;
char		buff[10];	
FILE	 	*fp;
int			nargs,i;

/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;


str=(char *)(malloc(sizeof(char)));
s=(struct SHDATA *)MK_FP(sh,0);
s=0;

x2=5;
y2=5;

fp=fopen(filenameI,"r");
for(i=0;i<norecords;i++)
{
		fread(&Delay,sizeof(struct INTERRUPTION),1,fp);

		PtSetParentWidget(ABW_Delay_List);
		Pos_d.x = x2;
		Pos_d.y = y2;
	
		PtSetArg( &args[0], Pt_ARG_POS, &Pos_d, 0 );
		Group_C[p2] = PtCreateWidget( PtGroup, NULL, 1, &args );    

		itoa((i+1),buff,10);
		TempDelay[i].iSerNo=Delay.iSerNo;

		nargs=0;
		Area_d.pos.y = 15;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 2, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_FLAGS,Pt_CURSOR_VISIBLE | Pt_TEXT_AUTO_HIGHLIGHT | Pt_EDITABLE | Pt_INSERT_MODE,Pt_FALSE);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d, 0);
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,buff , 0);
		Text[0][p2] = PtCreateWidget( PtLabel,Group_C[p2],nargs, &args );    

		strxfrm(TempDelay[i].sIntEvent,Delay.sIntEvent,14);

		nargs=0;
		Area_d.pos.y = 15;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 25, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_FLAGS,Pt_CURSOR_VISIBLE | Pt_TEXT_AUTO_HIGHLIGHT | Pt_EDITABLE | Pt_INSERT_MODE,Pt_FALSE);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d1, 0);
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,Delay.sIntEvent,0);
		Text[1][p2] = PtCreateWidget( PtText, Group_C[p2], nargs, &args );    

		TempDelay[i].lIntStartTime=Delay.lIntStartTime;

		str=(char *)(ctime(&Delay.lIntStartTime)+11);
		*(str+8)=0x00;

		nargs=0;
		Area_d.pos.y = 15;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 8, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_FLAGS,Pt_CURSOR_VISIBLE | Pt_TEXT_AUTO_HIGHLIGHT | Pt_EDITABLE | Pt_INSERT_MODE,Pt_FALSE);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d2, 0);
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,str , 0);
		Text[2][p2] = PtCreateWidget( PtText, Group_C[p2], nargs, &args );    

		TempDelay[i].lIntStopTime=Delay.lIntStopTime;

		str=(char *)(ctime(&Delay.lIntStopTime)+11);
		*(str+8)=0x00;

		nargs=0;
		Area_d.pos.y = 15;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 8, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_FLAGS,Pt_EDITABLE,Pt_FALSE );
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_FLAGS,Pt_CURSOR_VISIBLE | Pt_TEXT_AUTO_HIGHLIGHT | Pt_EDITABLE | Pt_INSERT_MODE,Pt_FALSE);
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,str , 0);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d2, 0);
		Text[3][p2] = PtCreateWidget( PtText, Group_C[p2], nargs, &args );    

		strxfrm(TempDelay[i].sDelayCode,Delay.sDelayCode,4);

		Pos_d.x = x2+400;
		Pos_d.y = y2;
		nargs=0;
		PtSetArg(&args[nargs++], Pt_ARG_POS, &Pos_d, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_MAX_LENGTH, 4, 0 );
		PtSetArg(&args[nargs++], Pt_ARG_FLAGS,Pt_SET | Pt_HIGHLIGHTED | Pt_GETS_FOCUS | Pt_FOCUS_RENDER,Pt_SET | Pt_HIGHLIGHTED | Pt_GETS_FOCUS | Pt_FOCUS_RENDER);
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_FLAGS,Pt_CURSOR_VISIBLE | Pt_TEXT_AUTO_HIGHLIGHT | Pt_EDITABLE | Pt_INSERT_MODE,Pt_CURSOR_VISIBLE | Pt_TEXT_AUTO_HIGHLIGHT | Pt_EDITABLE | Pt_INSERT_MODE);
		PtSetArg(&args[nargs++], Pt_ARG_DIM, &Dim_d3, 0);
		PtSetArg(&args[nargs++], Pt_ARG_TEXT_STRING,Delay.sDelayCode, 0);
		Text[4][p2] = PtCreateWidget( PtText, Group_C[p2], nargs, &args );  
		PtAddCallback(Text[4][p2], Pt_CB_REALIZED, &verify_uppernum, NULL);
		PtAddCallback(Text[4][p2], Pt_CB_ACTIVATE, &read_code, NULL);			


		PtRealizeWidget(Group_C[p2]);
		y2 = y2 + 21 ;				
		++p2;

		}

		PtContainerGiveFocus(Text[4][0],NULL);		



free(str);
fclose(fp);

return( Pt_CONTINUE );

}

int
init_int( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo )

{
int			i;
FILE		*fpd;


/* eliminate 'unreferenced' warnings */
widget = widget, apinfo = apinfo, cbinfo = cbinfo;

s=(struct SHDATA *)MK_FP(sh,0);
s=0;

if(bPastInt)
{
	unlink(filenameI);
	fpd=fopen(filenameI,"a+");
	for(i=0;i<p2;i++)
	{
   		memmove(&Delay,&TempDelay[i],sizeof(struct INTERRUPTION));
		fwrite(&Delay,sizeof(struct INTERRUPTION),1,fpd);
	}
	fclose(fpd);

// for(i=0;i<=p2-1;i++)
// PtDestroyWidget(Group_C[i]);
norecords=0;
bGetHeatFlg=FALSE;
PtContainerGiveFocus(ABW_cur_inf,NULL);

}

// else
// {
// for(i=0;i<=p2-1;i++)
// PtDestroyWidget(Group_I[i]);
// }

p2=0;
q2=0;
j=0;
ic=0;
k=0;
Onc=FALSE;
bPastInt=FALSE;

return( Pt_CONTINUE );

}

str=(char *)(malloc(sizeof(char)));

Then later str = ctime(…) which override the pointer str, hence when you do a free on str you are not doing a free on the pointer return by malloc by instead on the pointer return by ctime. I’m surprise its not crashing right away

This allocated only 1 bytes which seems odd, unfortunately because of smily I’m not sure what some of the code content really is (I couln’t find a way tro turn smilly off).

In

struct INTERRUPTION TempDelay[MAXINT];

What’s MAXINT.

There is LOTS of room in your program for failure. For example variable p2 is used to index array, and is incremented in bunch of places yet it’s only reset to 0 in init_int and I didn’t see any code that prevents p2 from getting bigger then the indexed array.