* Help on a memory leak issue
@ 2010-01-11 15:05 Uğur ATA
2010-01-11 20:17 ` ern0
2010-01-11 20:37 ` Glynn Clements
0 siblings, 2 replies; 4+ messages in thread
From: Uğur ATA @ 2010-01-11 15:05 UTC (permalink / raw)
To: linux-c-programming
Hi,
I have a client server application which uses a local file socket.
When i connect to the server part and then close the connection the
memory usage stays the same indicating that the resources aren't
freed. Other then this memory leak problem everything is working fine.
Messeages are sent and received. After each message is sent/received
rss indicator in the ps command increases with different amounts for
each different message. When the rss reaches around 64MB the program
stops working and freezes. Then it needs to be restarted.
I couldn't find a solution to this problem anywhere on the web so
thanks in advance if someone could be of help.
Below is the result of uname -a:
Linux server 2.6.27.7-smp #2 SMP Thu Nov 20 22:32:43 CST 2008 i686
Pentium III (Katmai) GenuineIntel GNU/Linux
Slackware 12.2 is running on that kernel and my source for the server part is:
<-------------
void wait_for_message() {
sigset_t waitset;
sigemptyset( &waitset );
sigaddset( &waitset, SIGALRM );
pthread_sigmask( SIG_BLOCK, &waitset, NULL );
int loop = 1;
// use local socket
int socket_fd = socket(PF_UNIX, SOCK_STREAM, 0);
struct sockaddr_un name;
/* Indicate that this is a server. */
name.sun_family = AF_LOCAL;
strcpy(name.sun_path, SOCKET); // use socket file
bind(socket_fd, &name, SUN_LEN(&name));
// maximum number of requests stacked
listen(socket_fd, 10);
do {
struct sockaddr_un client_name;
socklen_t client_name_len = 0; // it should be >= 0 otherwise
accept returns EINVAL
int client_socket_fd;
client_socket_fd = accept(socket_fd, &client_name, &client_name_len);
if (read(client_socket_fd, &length, sizeof (length)) > 0) {
.....
}
shutdown(client_socket_fd, SHUT_RDWR);
close(client_socket_fd);
} while (loop);
/* Remove the socket file. */
close(socket_fd);
unlink(SOCKET);
-------------->
and the client part is:
char* sendMessage(char* message) {
char* result = NULL;
int length = strlen(message) + 1;
if (message == NULL || length <= 0) {
return NULL;
}
int socket_fd;
struct sockaddr_un name;
socket_fd = socket(PF_LOCAL, SOCK_STREAM, 0);
name.sun_family = AF_LOCAL;
strcpy(name.sun_path, SOCKET);
connect(socket_fd, &name, SUN_LEN(&name));
// write length of the message
write(socket_fd, &length, sizeof (length));
//write message itself
write(socket_fd, message, length);
length = 0;
// read length of the result
read(socket_fd, &length, sizeof(length));
if (length > 0) {
......
}
shutdown(socket_fd, SHUT_RDWR);
close(socket_fd);
return result;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help on a memory leak issue
2010-01-11 15:05 Help on a memory leak issue Uğur ATA
@ 2010-01-11 20:17 ` ern0
2010-01-11 20:37 ` Glynn Clements
1 sibling, 0 replies; 4+ messages in thread
From: ern0 @ 2010-01-11 20:17 UTC (permalink / raw)
To: linux-c-programming
> I have a client server application which uses a local file socket.
> When i connect to the server part and then close the connection the
> memory usage stays the same indicating that the resources aren't
> freed. Other then this memory leak problem everything is working fine.
I assume, the memleak is not in the part of the code you've been sent,
but who knows. Let's exclude that case.
If I were you, I would change the server code to a short one, which
sends back a dummy simple "ok" or "fail" message (the simpler one), I
guess, the "..." part of your code is that place:
if (read(client_socket_fd, &length, sizeof (length)) > 0) {
.....
}
Then fire as many request as you can, and check the mem.
--
ern0.scene.plus4.amiga.code.muzak
Haben Sie Fragen?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help on a memory leak issue
2010-01-11 15:05 Help on a memory leak issue Uğur ATA
2010-01-11 20:17 ` ern0
@ 2010-01-11 20:37 ` Glynn Clements
2010-01-12 8:02 ` Sam Liao
1 sibling, 1 reply; 4+ messages in thread
From: Glynn Clements @ 2010-01-11 20:37 UTC (permalink / raw)
To: Uğur ATA; +Cc: linux-c-programming
Uğur ATA wrote:
> I have a client server application which uses a local file socket.
> When i connect to the server part and then close the connection the
> memory usage stays the same indicating that the resources aren't
> freed. Other then this memory leak problem everything is working fine.
> Messeages are sent and received. After each message is sent/received
> rss indicator in the ps command increases with different amounts for
> each different message. When the rss reaches around 64MB the program
> stops working and freezes. Then it needs to be restarted.
> I couldn't find a solution to this problem anywhere on the web so
> thanks in advance if someone could be of help.
> Below is the result of uname -a:
> Linux server 2.6.27.7-smp #2 SMP Thu Nov 20 22:32:43 CST 2008 i686
> Pentium III (Katmai) GenuineIntel GNU/Linux
> Slackware 12.2 is running on that kernel and my source for the server part is:
Whatever is causing the leak isn't in the portion of the code which
you posted.
Also:
> struct sockaddr_un client_name;
> socklen_t client_name_len = 0; // it should be >= 0 otherwise accept returns EINVAL
> int client_socket_fd;
> client_socket_fd = accept(socket_fd, &client_name, &client_name_len);
If you want accept to initialise client_name, you should initialise
client_name_len to the size of the buffer, i.e.:
client_name_len = sizeof client_name;
--
Glynn Clements <glynn@gclements.plus.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help on a memory leak issue
2010-01-11 20:37 ` Glynn Clements
@ 2010-01-12 8:02 ` Sam Liao
0 siblings, 0 replies; 4+ messages in thread
From: Sam Liao @ 2010-01-12 8:02 UTC (permalink / raw)
To: Glynn Clements; +Cc: Uğur ATA, linux-c-programming
Instead of read each line in details, have a try for valgrind.
-Sam
On Tue, Jan 12, 2010 at 4:37 AM, Glynn Clements
<glynn@gclements.plus.com> wrote:
>
> Uğur ATA wrote:
>
>> I have a client server application which uses a local file socket.
>> When i connect to the server part and then close the connection the
>> memory usage stays the same indicating that the resources aren't
>> freed. Other then this memory leak problem everything is working fine.
>> Messeages are sent and received. After each message is sent/received
>> rss indicator in the ps command increases with different amounts for
>> each different message. When the rss reaches around 64MB the program
>> stops working and freezes. Then it needs to be restarted.
>> I couldn't find a solution to this problem anywhere on the web so
>> thanks in advance if someone could be of help.
>> Below is the result of uname -a:
>> Linux server 2.6.27.7-smp #2 SMP Thu Nov 20 22:32:43 CST 2008 i686
>> Pentium III (Katmai) GenuineIntel GNU/Linux
>> Slackware 12.2 is running on that kernel and my source for the server part is:
>
> Whatever is causing the leak isn't in the portion of the code which
> you posted.
>
> Also:
>
>> struct sockaddr_un client_name;
>> socklen_t client_name_len = 0; // it should be >= 0 otherwise accept returns EINVAL
>> int client_socket_fd;
>> client_socket_fd = accept(socket_fd, &client_name, &client_name_len);
>
> If you want accept to initialise client_name, you should initialise
> client_name_len to the size of the buffer, i.e.:
>
> client_name_len = sizeof client_name;
>
> --
> Glynn Clements <glynn@gclements.plus.com>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-01-12 8:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-11 15:05 Help on a memory leak issue Uğur ATA
2010-01-11 20:17 ` ern0
2010-01-11 20:37 ` Glynn Clements
2010-01-12 8:02 ` Sam Liao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).