dbTalk Databases Forums  

Memory leak in the Open Server or incorrect exit?

comp.databases.sybase comp.databases.sybase


Discuss Memory leak in the Open Server or incorrect exit? in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Alex
 
Posts: n/a

Default Memory leak in the Open Server or incorrect exit? - 12-18-2003 , 12:28 PM






The program below is a very simple and useless Open Server application
- it starts and waits for only one request - "stop", then it exits.
--------------------------------------------------------------------------------

#include <iostream.h>
#include <cspublic.h>
#include <ospublic.h>

static char Interfaces[] = "/sybase/interfaces";
static char ServerName[] = "EMARD_RS_DEV";
static char StopName[] = "stop";

const CS_INT Version = CS_VERSION_110;

static CS_CONTEXT* CtxPtr = 0;

extern "C" CS_RETCODE Stop (SRV_PROC* PTR)
{
cout << "Stop called" << endl;
srv_senddone (PTR, SRV_DONE_FINAL, CS_TRAN_COMPLETED, 0);
srv_event (PTR, SRV_STOP, 0);
return CS_SUCCEED;
}

extern "C" CS_RETCODE EventHandlerStart (SRV_SERVER* PTR)
{
CS_RETCODE rc;
cout << "Event received (SRV_START)" << endl;
SRV_PROC* procPtr = srv_createproc (PTR);
rc = srv_regdefine (procPtr, (CS_CHAR*) StopName, CS_NULLTERM,
Stop);
cout << "srv_regdefine " << rc << endl;
rc = srv_regcreate (procPtr, 0);
cout << "srv_regcreate " << rc << endl;
srv_dropproc (procPtr);
return CS_SUCCEED;
}

int main (void)
{
CS_RETCODE retcode = cs_ctx_global (Version, &CtxPtr);
if (retcode == CS_SUCCEED)
{
cout << "Context allocated" << endl;
retcode = srv_version (CtxPtr, Version);
if (retcode == CS_SUCCEED)
{
cout << "Server version set" << endl;
srv_props (CtxPtr, CS_SET, SRV_S_IFILE, Interfaces, CS_NULLTERM,
0);
if (srv_init (0, ServerName, CS_NULLTERM) != 0)
{
cout << "Server initialized" << endl;
srv_handle (0, SRV_START, EventHandlerStart);
retcode = srv_run (0);
if (retcode != CS_SUCCEED)
{
cout << "Server isn't running, retcode = " << retcode <<
endl;
}
}
else
{
cout << "Server isn't initialized" << endl;
}
}
else
{
cout << "Server version isn't set, retcode = " << retcode <<
endl;
}
cs_ctx_drop (CtxPtr);
}
else
{
cout << "Context isn't allocated, retcode = " << retcode << endl;
}
}

-------------------------------------------------------------------------------
I compiled this program in Sun Solaris 2.8 by the Forte Developer 6U2,
and linked it with Sybase 12.5 Open Client/Server libraries
(EBF11305), then I ran this application from within the Forte Debugger
with "Memuse Checking" enabled. The result is below - it shows large
memory leaks:
-------------------------------------------------------------------------------

Actual leaks report (actual leaks: 5 total size: 104904
bytes)
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x572520
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv_spawn<-srv_run<-main
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x583550
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv__conservice<-srv__spawnfunc<-0x03a370
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x58bd68
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv__start_subchannel<-srv__complete_siteread<-srv__runsite<-
srv__connhandle<-srv__spawnfunc<-0x03a370
Memory Leak (mel):
Found leaked block of size 300 bytes at address 0x2a3da0
At time of allocation, the call stack was:
srv_alloc<-srv_init<-main
Memory Leak (mel):
Found leaked block of size 156 bytes at address 0x550038
At time of allocation, the call stack was:
srv_alloc<-srv__add_ent<-srv__act_createmsgq<-srv__createproc<-srv_spawn<-srv_run<-main

--------------------------------------------------------------------------------
So, my questions:

(1) Is it really a memory leak? How to avoid it?
(2) May be, the Open Server application should clean after itself
before exit. How to do that?

Thanks in advance,
Aleksey

Reply With Quote
  #2  
Old   
Neal
 
Posts: n/a

Default Re: Memory leak in the Open Server or incorrect exit? - 12-19-2003 , 01:36 PM






Hello,

Your use of "0" as the first parameter for some of the "srv_" functions
may be causing some problems. I know Sybase does not test that way.
In most cases they pass a valid pointer.

I don't know if you are linking your application with the thread-safe
libraries (they have the "_r" extension) or nonthread-safe. With
past memory leak cases, it has made a difference as to which libraries
you are using.

I think you should test using the Open Server sample program "lang.c"
and tell us which libraries you linked with.

Most of the structures that it is complaining about look like structures
that are allocated during the initialization phase and are not explicitly
freed. Rather, they look like they are released once the Open Server exits.

That might be considered sloppy but I would be much more concerned
if there were a memory leak in an area where you have repeated activity.
In other words if there were a leak each time a client connected, executed
an RPC and disconnected, I would be more worried. I have tested applications
that repeat these types of sequences 1000's of times but I have not seen
any significant memory wasted.

yakovlev (AT) hotmail (DOT) com (Alex) wrote in message news:<fdded1aa.0312181028.7217563e (AT) posting (DOT) google.com>...
Quote:
The program below is a very simple and useless Open Server application
- it starts and waits for only one request - "stop", then it exits.
--------------------------------------------------------------------------------

#include <iostream.h
#include <cspublic.h
#include <ospublic.h

static char Interfaces[] = "/sybase/interfaces";
static char ServerName[] = "EMARD_RS_DEV";
static char StopName[] = "stop";

const CS_INT Version = CS_VERSION_110;

static CS_CONTEXT* CtxPtr = 0;

extern "C" CS_RETCODE Stop (SRV_PROC* PTR)
{
cout << "Stop called" << endl;
srv_senddone (PTR, SRV_DONE_FINAL, CS_TRAN_COMPLETED, 0);

srv_event (PTR, SRV_STOP, 0);
return CS_SUCCEED;
}

extern "C" CS_RETCODE EventHandlerStart (SRV_SERVER* PTR)
{
CS_RETCODE rc;
cout << "Event received (SRV_START)" << endl;
SRV_PROC* procPtr = srv_createproc (PTR);
rc = srv_regdefine (procPtr, (CS_CHAR*) StopName, CS_NULLTERM,
Stop);
cout << "srv_regdefine " << rc << endl;
rc = srv_regcreate (procPtr, 0);
cout << "srv_regcreate " << rc << endl;
srv_dropproc (procPtr);
return CS_SUCCEED;
}

int main (void)
{
CS_RETCODE retcode = cs_ctx_global (Version, &CtxPtr);
if (retcode == CS_SUCCEED)
{
cout << "Context allocated" << endl;
retcode = srv_version (CtxPtr, Version);
if (retcode == CS_SUCCEED)
{
cout << "Server version set" << endl;
srv_props (CtxPtr, CS_SET, SRV_S_IFILE, Interfaces, CS_NULLTERM,
0);
if (srv_init (0, ServerName, CS_NULLTERM) != 0)
{
cout << "Server initialized" << endl;
srv_handle (0, SRV_START, EventHandlerStart);
retcode = srv_run (0);
if (retcode != CS_SUCCEED)
{
cout << "Server isn't running, retcode = " << retcode
endl;
}
}
else
{
cout << "Server isn't initialized" << endl;
}
}
else
{
cout << "Server version isn't set, retcode = " << retcode
endl;
}
cs_ctx_drop (CtxPtr);
}
else
{
cout << "Context isn't allocated, retcode = " << retcode << endl;
}
}

-------------------------------------------------------------------------------
I compiled this program in Sun Solaris 2.8 by the Forte Developer 6U2,
and linked it with Sybase 12.5 Open Client/Server libraries
(EBF11305), then I ran this application from within the Forte Debugger
with "Memuse Checking" enabled. The result is below - it shows large
memory leaks:
-------------------------------------------------------------------------------

Actual leaks report (actual leaks: 5 total size: 104904
bytes)
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x572520
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv_spawn<-srv_run<-main
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x583550
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv__conservice<-srv__spawnfunc<-0x03a370
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x58bd68
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv__start_subchannel<-srv__complete_siteread<-srv__runsite<-
srv__connhandle<-srv__spawnfunc<-0x03a370
Memory Leak (mel):
Found leaked block of size 300 bytes at address 0x2a3da0
At time of allocation, the call stack was:
srv_alloc<-srv_init<-main
Memory Leak (mel):
Found leaked block of size 156 bytes at address 0x550038
At time of allocation, the call stack was:
srv_alloc<-srv__add_ent<-srv__act_createmsgq<-srv__createproc<-srv_spawn<-srv_run<-main

--------------------------------------------------------------------------------
So, my questions:

(1) Is it really a memory leak? How to avoid it?
(2) May be, the Open Server application should clean after itself
before exit. How to do that?

Thanks in advance,
Aleksey

Reply With Quote
  #3  
Old   
Alex
 
Posts: n/a

Default Re: Memory leak in the Open Server or incorrect exit? - 01-15-2004 , 03:10 PM



lucky_justin69 (AT) yahoo (DOT) com (Neal) wrote in message news:<498321de.0312191136.75e12a26 (AT) posting (DOT) google.com>...
Quote:
Hello,

Your use of "0" as the first parameter for some of the "srv_" functions
may be causing some problems. I know Sybase does not test that way.
In most cases they pass a valid pointer.

I don't know if you are linking your application with the thread-safe
libraries (they have the "_r" extension) or nonthread-safe. With
past memory leak cases, it has made a difference as to which libraries
you are using.

I think you should test using the Open Server sample program "lang.c"
and tell us which libraries you linked with.

Most of the structures that it is complaining about look like structures
that are allocated during the initialization phase and are not explicitly
freed. Rather, they look like they are released once the Open Server exits.

That might be considered sloppy but I would be much more concerned
if there were a memory leak in an area where you have repeated activity.
In other words if there were a leak each time a client connected, executed
an RPC and disconnected, I would be more worried. I have tested applications
that repeat these types of sequences 1000's of times but I have not seen
any significant memory wasted.

yakovlev (AT) hotmail (DOT) com (Alex) wrote in message news:<fdded1aa.0312181028.7217563e (AT) posting (DOT) google.com>...
The program below is a very simple and useless Open Server application
- it starts and waits for only one request - "stop", then it exits.
--------------------------------------------------------------------------------

#include <iostream.h
#include <cspublic.h
#include <ospublic.h

static char Interfaces[] = "/sybase/interfaces";
static char ServerName[] = "EMARD_RS_DEV";
static char StopName[] = "stop";

const CS_INT Version = CS_VERSION_110;

static CS_CONTEXT* CtxPtr = 0;

extern "C" CS_RETCODE Stop (SRV_PROC* PTR)
{
cout << "Stop called" << endl;
srv_senddone (PTR, SRV_DONE_FINAL, CS_TRAN_COMPLETED, 0);

srv_event (PTR, SRV_STOP, 0);
return CS_SUCCEED;
}

extern "C" CS_RETCODE EventHandlerStart (SRV_SERVER* PTR)
{
CS_RETCODE rc;
cout << "Event received (SRV_START)" << endl;
SRV_PROC* procPtr = srv_createproc (PTR);
rc = srv_regdefine (procPtr, (CS_CHAR*) StopName, CS_NULLTERM,
Stop);
cout << "srv_regdefine " << rc << endl;
rc = srv_regcreate (procPtr, 0);
cout << "srv_regcreate " << rc << endl;
srv_dropproc (procPtr);
return CS_SUCCEED;
}

int main (void)
{
CS_RETCODE retcode = cs_ctx_global (Version, &CtxPtr);
if (retcode == CS_SUCCEED)
{
cout << "Context allocated" << endl;
retcode = srv_version (CtxPtr, Version);
if (retcode == CS_SUCCEED)
{
cout << "Server version set" << endl;
srv_props (CtxPtr, CS_SET, SRV_S_IFILE, Interfaces, CS_NULLTERM,
0);
if (srv_init (0, ServerName, CS_NULLTERM) != 0)
{
cout << "Server initialized" << endl;
srv_handle (0, SRV_START, EventHandlerStart);
retcode = srv_run (0);
if (retcode != CS_SUCCEED)
{
cout << "Server isn't running, retcode = " << retcode
endl;
}
}
else
{
cout << "Server isn't initialized" << endl;
}
}
else
{
cout << "Server version isn't set, retcode = " << retcode
endl;
}
cs_ctx_drop (CtxPtr);
}
else
{
cout << "Context isn't allocated, retcode = " << retcode << endl;
}
}

-------------------------------------------------------------------------------
I compiled this program in Sun Solaris 2.8 by the Forte Developer 6U2,
and linked it with Sybase 12.5 Open Client/Server libraries
(EBF11305), then I ran this application from within the Forte Debugger
with "Memuse Checking" enabled. The result is below - it shows large
memory leaks:
-------------------------------------------------------------------------------

Actual leaks report (actual leaks: 5 total size: 104904
bytes)
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x572520
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv_spawn<-srv_run<-main
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x583550
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv__conservice<-srv__spawnfunc<-0x03a370
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x58bd68
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv__start_subchannel<-srv__complete_siteread<-srv__runsite<-
srv__connhandle<-srv__spawnfunc<-0x03a370
Memory Leak (mel):
Found leaked block of size 300 bytes at address 0x2a3da0
At time of allocation, the call stack was:
srv_alloc<-srv_init<-main
Memory Leak (mel):
Found leaked block of size 156 bytes at address 0x550038
At time of allocation, the call stack was:
srv_alloc<-srv__add_ent<-srv__act_createmsgq<-srv__createproc<-srv_spawn<-srv_run<-main

--------------------------------------------------------------------------------
So, my questions:

(1) Is it really a memory leak? How to avoid it?
(2) May be, the Open Server application should clean after itself
before exit. How to do that?

Thanks in advance,
Aleksey
Neal,

I've compiled the sample program lang.c in Solaris 8, compiler was
"Sun WorkShop 6 update 2 C 5.3 2001/05/15", makefile is below:

CFLAGS += -I${SYBASE}/${SYBASE_OCS}/include -I. -g
LDLIBS += -L${SYBASE}/${SYBASE_OCS}/lib -lsrv -lct -lcs -ltcl -lcomn
-lintl

..SUFFIXES: .o .c

..c: ;${CC} ${CFLAGS} ${LDFLAGS} $< -o $@ ${LDLIBS}
..c.o: ;${CC} ${CFLAGS} -c $<

clean:
rm -f core *% *.o *.log lang

lang: utils.o lang.o
${CC} ${LDFLAGS} -o lang utils.o lang.o ${LDLIBS}

I've started the lang program from the Forte Developer 6U2 in
debugging mode with "memuse checking" enabled, and then I issued the
"stop_srv" command from the Sybase ASE 12.5. The reported memory leaks
are below:

Actual leaks report (actual leaks: 5 total size: 104904
bytes)
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x454f18
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv_spawn<-srv_run<-main
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x465f48
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv__conservice<-srv__spawnfunc<-0xfd55a04c
Memory Leak (mel):
Found leaked block of size 34816 bytes at address 0x46e760
At time of allocation, the call stack was:
srv_alloc<-srv__assign_stack<-srv__spawn<-srv__start_subchannel<-srv__complete_siteread<-srv__runsite<-srv__connhandle<-srv__spawnfunc<-0xfd55a04c
Memory Leak (mel):
Found leaked block of size 300 bytes at address 0x186850
At time of allocation, the call stack was:
srv_alloc<-srv_init<-main
Memory Leak (mel):
Found leaked block of size 156 bytes at address 0x432fe8
At time of allocation, the call stack was:
srv_alloc<-srv__add_ent<-srv__act_createmsgq<-srv__createproc<-srv_spawn<-srv_run<-main

I agree with you that this problem is not very serious. I just would
like to have a clean memory leak report for my applications. I hoped
I'd be able to achieve that with some modifications in the exit
procedure.

Could you please advise?

Thanks,
Alex


Reply With Quote
  #4  
Old   
Neal
 
Posts: n/a

Default Re: Memory leak in the Open Server or incorrect exit? - 01-16-2004 , 11:14 AM



Hello,

I filed a bug for this problem:
344035 - Open Server leaks memory when shut down in STOP_SRV event

Without a technical support case to attach the bug to,
the bug will have zero priority in engineering so I
can't give any estimate as to when the bug will be fixed.

If you need it fixed soon, I recommend logging a case with
Sybase technical support and request that it be fixed.

Thanks,
Neal

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.