![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |