Subject: sftp functions leaking memory?

sftp functions leaking memory?

From: Marta <>
Date: Fri, 18 May 2012 12:34:08 +0200


Let's see if you can enlighten my day :)

A bit of background: I'm working with an embedded system[1] and I
needed a library to manage sftp transfers that need to be done
periodically, so I used libssh2. Everything was going smooth until I
realized the process was eating memory, around 2 MB a day. That's not
a big deal on a bigger system, but having only 64 MB of RAM, in my
case that is a problem.

I reviewed my code, and having not found any error, I tried to make
some measurements with one of the examples. I modified the non
blocking sftp example to operate in a loop (see attachment, if you
want to compile it you will have to change the pmemlog string to match
your system, and include the right libssh2_config.h). After 433
iterations, I made a graph of the heap size. The heap growth is almost
linear, and it does not seem to stabilize. Another interesting thing
is that the heap does not grow on each iteration. You can see the
details on the attached spreadsheet.

More data:
- I've already searched the list for something similar to this...
without success.
- I've tested this in libssh2-1.3.0, libssh2-1.4.1 and libssh2-1.4.2
(yesterdays' morning snapshot, the zombies thing gave me hope... )
- Compiled with libgcrypt 1.5.0 (also tried with openssl, the leak was
also present).
- My cross-compiler is a bit old, but I'm not allowed to use another
for now (In my paranoia I'm tempted to blame the compiler)
# arm-linux-gcc --v
Reading specs from /usr/local/lib/gcc-lib/arm-linux/3.3.2/specs
Configured with: ../configure --target=arm-linux --disable-shared
--with-gnu-as --with-gnu-ld --enable-multilib
Thread model: posix
gcc version 3.3.2

If you have any idea on this, I will be very happy to read it. If not,
I will have to dive into the code to find an explanation for this...

Thank you very much!

[1] -


Received on 2012-05-18