Author |
Message
|
Sabbi |
Posted: Wed Jan 30, 2008 2:28 am Post subject: Memory leak with MQ C++ APIs |
|
|
Newbie
Joined: 30 Jan 2008 Posts: 3
|
Hi,
I have developed an application using Web sphere MQ C++ imq classes.
All this application does is in a while loop open the queue and browse the message (message will not be deleted after reading) using full buffer read method and closes the queue connection.
After running this application for about 2 to 3 hours with one message in the queue in AIX platform application is exiting with core dump because of memory leak. This is working fine in SunOS.
Please suggest me why this is happening, I have used MQ 5.3 and also tried with 6.0 as well.
Many thanks,
Sabbi |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jan 30, 2008 2:37 am Post subject: Re: Memory leak with MQ C++ APIs |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Sabbi wrote: |
Please suggest me why this is happening |
There's a memory leak in the AIX MQ imq class? Just a guess!
A good question is why you're doing this? What is the function of a program that sits and browses the first message on a queue for 2 - 3 hours? Opening and closing the queue while it does it? Aside from eating resources what's the point? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jan 30, 2008 3:45 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
It's a memory leak in your application.
It shows up under AIX rather than SunOS because they use different memory models.
Connect once when your program starts. Disconnect when your program is done with MQ.
Open a queue that you need to get or put to once. Close it when you're done.
Loop over a GET/PUT.
Make sure you dispose of any memory that you allocate. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
tleichen |
Posted: Wed Jan 30, 2008 7:41 am Post subject: |
|
|
Yatiri
Joined: 11 Apr 2005 Posts: 663 Location: Center of the USA
|
Also, just because you do not realize the memory leak on SunOS, does not mean it is not occurring. Like Jeff stated, they are different memory models and maybe it just happens to be more tolerant of your error, either through the O/S design or because of the particular configuration of that system, i.e., stack space, handles available, etc.  _________________ IBM Certified MQSeries Specialist
IBM Certified MQSeries Developer |
|
Back to top |
|
 |
Sabbi |
Posted: Thu Jan 31, 2008 11:05 pm Post subject: |
|
|
Newbie
Joined: 30 Jan 2008 Posts: 3
|
Thanks for your posting..
We have designed opening the queue every time and closing after reading, because of initial design was to open the queue only if we have data in the tables. Later we got change request for browsing another queue without deleting message and updating the tables.
Since our initial design is to opening and closing every time we continued the same for this queue as well.
Is this caused the problem of memory leak or way we are reading the message we used.
Please find the piece of code below used for reading the message:
//Allocating memory to buffer depending on the message length
buffer=(char*)malloc((msg.length()+1)*sizeof(char));
//If memory is allocated prperly to the buffer then copy the
//message in the buffer.
if(buffer!=NULL)
{
memset(buffer,'\0',(msg.length()+1)*sizeof(char));
strcpy(buffer,msg);
//Set the buffer pointer to point to the external buffer
message.useFullBuffer(buffer,(msg.length())*sizeof(char));
//Set the format of the message as a simple string format
message.setFormat(MQFMT_STRING);
//Call to put the message on the queue.
//If any error then call the error handler and set the return value
//to FALSE
if(!_queue.put(message))
{
_ErrorHandler(funcName,IQ_MQ_Q);
returnVal=FALSE;
}
//Free the allocated memory
free(buffer);
buffer=NULL;
} |
|
Back to top |
|
 |
Vitor |
Posted: Fri Feb 01, 2008 1:37 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Sabbi wrote: |
Is this caused the problem of memory leak or way we are reading the message we used.
|
I think one problem is, if I'm reading the code correctly, you're trying to read the message with a put method.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Sabbi |
Posted: Thu Feb 07, 2008 7:55 am Post subject: |
|
|
Newbie
Joined: 30 Jan 2008 Posts: 3
|
Sorry the code which I send is for putting message, but same code with get is used for reading message.
That wroked fine.. my question is does full buffer leaves any memory leak.
About changing of logic instead fo opening and reading the queue every time open once and just read every time using same connection. Now the code is already delivered to the client with this memoy leak. If you feel that this memory leak vanish after changing the logic we are ready to change.
Please advice us.
Thanks,
Sabbi |
|
Back to top |
|
 |
Vitor |
Posted: Thu Feb 07, 2008 8:09 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Sabbi wrote: |
About changing of logic instead fo opening and reading the queue every time open once and just read every time using same connection. Now the code is already delivered to the client with this memoy leak. If you feel that this memory leak vanish after changing the logic we are ready to change. |
At best this design will chew resources and impact performance because it's inefficent.
At worst it's causing this leak. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Feb 07, 2008 9:23 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You shouldn't be basing "Does this fix the memory leak" based on our opinions.
You should be basing it on the testing you have done. Which should have shown the memory leak in the first place. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|