I have a program that basically does this: smbc_init(...); while (true) { for (IP = "172.31.[57-60,65].[1-245]") { cout << "Scanning <ip>"; if (smbc_open("smb://<ip>/") succeeds) { cout << "Share: <share>"; // Read a list of shares, and scan the shares for all the files. // All the files are correctly closed. } } cout << "Reinitialising libsmbclient"; context = smbc_set_context(NULL); smbc_free_context(context, TRUE); if (smbc_init(my_auth_data_fn, debug_level) != 0) { cout << "error"; return 1; } } But obviously more correctly. With the extra reinitialisation the scan works the first time, then has lots of broken pipes before scanning the second time (ie between the first and second scans). On the second scan it can't connect to *any* hosts. The second time it reinitialises the program segfaults (possibly because context is NULL). I'll attach a sample output.
Created attachment 1573 [details] Output of smb scanner. This is the output from my scanning program.
Solved it using this to reinitialise libsmbclient. It still says all the errors but then it works the next time anyway. SMBCCTX* context = smbc_set_context(NULL); // Retrieve current context if (!context) cout << "Error! Context was null." << endl; smbc_free_context(context, true); // Close all cached connections SMBCCTX *statcont1 = smbc_new_context(); if (!statcont1) { cout << "Error creating new context." << endl; return 1; } statcont1->debug = 1; statcont1->callbacks.auth_fn = guest_auth_smbc_get_data; if (!smbc_init_context(statcont1)) { cout << "Error initialising new context." << endl; smbc_free_context(statcont1, false); return 1; } smbc_set_context(statcont1);
Problem appears to have been a file descriptor leak. Thanks for the report. Please test from SVN and reopen bug if problem persists.