login about faq


The CkSFtp::openDir() (C++ library, 9.5.0-x86-vc9) when using it for more than 10 times.
Using it as in the example, it works correctly for the first 10 usage, with readDir() and Closehandle() working correctly as well.
The simplest code below also fails at 10th iteration:
// After successful connect and authenticate
for (int i = 0; i < 20; i++)
const char* hDir = sftp.openDir(".");

Tried with various SSH/SFTP servers, and the behaviour is the same.

As another question, when using CkSFtp::OpenDir(), which returns a bool and a CkString as output parameter, what handle should be used in CkSFtp::CloseHandle()?


asked Aug 04 '16 at 03:36

szbalazs's gravatar image


 CkSFtp::OpenDir(), which returns a bool and a CkString as output parameter

The CkString output parameter is the handle (that should be closed).

Please post the output of lastErrorText ( https://www.chilkatsoft.com/refdoc/vcCkSFtpDoc.html#prop33 ) you get after the failing openDir call.

(Aug 04 '16 at 04:37) Gert ♦

There is no lastErrorText() of the failed call of openDir(), as an exception is raised in the ChilKat lib, because of HEAP memory corruption.
If the openDir() is placed in a try{}, the lastErrorText() executed in the catch(...) handler reports the previous successful call of the CloseHandle()

(Aug 04 '16 at 05:27) szbalazs

Problem found, in my code.
Previous to the example code above there was the code segment below:
const char *absPath = sftp.realPath(".","");
//save absolute path
delete absPath;
As it turned out, the "delete" is not needed, most probably it uses the same internal pool of buffers as openDir(), which was destroyed, but the same pointer was reused in openDir().


answered Aug 11 '16 at 06:18

szbalazs's gravatar image


See this: http://cknotes.com/chilkat-c-api-lowercase-methods-returning-const-char/

I tested your simplest code, and everything works perfectly.

The reason the 11th try would fail is because there are 10 internal pointers that are recycled for the lowercase method calls.

For example:

const char ptr1 = chilkatObject.lowerCaseMethodReturningString(xyz);
const char ptr2 = chilkatObject.lowerCaseMethodReturningString(xyz);
const char ptr3 = chilkatObject.lowerCaseMethodReturningString(xyz);
const char ptr4 = chilkatObject.lowerCaseMethodReturningString(xyz);
const char ptr10 = chilkatObject.lowerCaseMethodReturningString(xyz);
// After the next call, ptr1 is no longer valid!
const char ptr11 = chilkatObject.lowerCaseMethodReturningString(xyz);

As described on the web page at the link above:

Important: The lowercase alternative that returns a “const char ” is returning a pointer to internal memory that is not permanent. Your application should make use of it immediately and then discard the pointer. If the string is needed for a longer amount of time, then it should be copied to memory owned and controlled by the application, or the upper-case alternative using CkString should be used instead. If an application keeps a “const char ” pointer and continues to make additional calls on the same Chilkat object instance, the memory pointed to by the “const char *” could change.


answered Aug 04 '16 at 10:08

chilkat's gravatar image

chilkat ♦♦

The const char pointer's value returned by the openDir() (or any information it could be accessed with it) is not used by application (or it is extracted to own variables) after the calling of CloseHandle(), the next iteration of openDir() should return a new valid value, regardless of the iteration count, right? There is only one (the last) pointer value used at a time. What is the purpose of CloseHandle(), if not to release the pointer (free memory?)? Is there an additional 'delete' needed?

(Aug 04 '16 at 11:15) szbalazs

Please review your answer and my previous comment, as your answer does not explain the problem described. Thanks

(Aug 09 '16 at 05:08) szbalazs
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Aug 04 '16 at 03:36

Seen: 1,322 times

Last updated: Aug 11 '16 at 06:18

powered by OSQA