-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak with gp_port_info_list_new()
/gp_port_info_list_load()
and GPPortInfoList
#208
Comments
You've got a memory leak. I tried using only the |
I tried reproducing it, but failed. running above code 100 times does not change leakage compared to 1 time. (I used 2.5.16 and 2.5.12 ... ) It is weird, which libusb version is used? |
Looks like I'm out of date. |
I'm still having issues with this. Can you tell me which version of |
libusb 1.0 is curently the one to be used, libusb 0.1 is deprecated for a while now |
Here's the one I have installed right now:
I'm still having the same problem. Is anyone else able to confirm this? |
Okay, so I grabbed the latest copy of ubuntu (server) 18.04 and did a fresh install (with the latest updates too). installed both #include <vector>
#include <string>
using namespace std;
#include <unistd.h>
#include "gphoto2/gphoto2.h"
void scan() {
GPContext *scanContext;
CameraList *camList;
GPPortInfoList *portList;
CameraAbilitiesList *abilitiesList;
CameraAbilities abilities;
const char *name, *value;
// Init
scanContext = gp_context_new();
gp_list_new(&camList);
gp_port_info_list_new(&portList);
gp_abilities_list_new(&abilitiesList);
/*
// Query
gp_port_info_list_load(portList); // I think the memory leak is coming from here
gp_abilities_list_load(abilitiesList, scanContext);
gp_abilities_list_detect(abilitiesList, portList, camList, scanContext);
// See how many we got
int numCams = gp_list_count(camList);
vector<string> names;
vector<string> ports;
for (int i = 0; i < numCams; i++) {
// Pull out some info
gp_list_get_name(camList, i, &name);
gp_list_get_value(camList, i, &value);
// Init data
gp_abilities_list_get_abilities(abilitiesList, i, &abilities);
// Store it in the list If it's a camera
if (abilities.device_type == GP_DEVICE_STILL_CAMERA) {
names.push_back(string(name));
ports.push_back(string(value));
}
}
*/
// Cleanup GPhoto2 data
gp_list_unref(camList);
gp_port_info_list_free(portList);
gp_abilities_list_free(abilitiesList);
gp_context_unref(scanContext);
}
int main() {
// Run forever
while (true) {
scan();
usleep(1000 * 10); // 1/100th of a second
}
return 0;
} If you run the above code, there will be no memory leaks and the program will keep on chugging along forever, or until you kill it. But if you uncomment the line where I ran |
one question, is a device being present while you run this loop? |
With my VM, I did not have a device plugged in. I can test it again with a device later, but I'm away from the VM right now. |
gp_port_info_list_new()
and GPPortInfoList
gp_port_info_list_new()
/gp_port_info_list_load()
and GPPortInfoList
gp_port_info_list_new()
/gp_port_info_list_load()
and GPPortInfoList
gp_port_info_list_new()
/gp_port_info_list_load()
and GPPortInfoList
I can confirm some leaks at least. lets see what I find |
Hi. Have you been able to investigate this further? I have no problem submitting a PR to fix this, but I haven't investigated it any more deeper than the |
I should paste in some
My suspicion is that it's with something in this function:
|
Hi, @define-private-public |
Hi, I haven't looked at this in a bit (as I'm now using a somewhat hacky solution to get around this problem). I do think the cause it related somehow to how |
Im also interested in this issue, I have seen the revision numbers moving for both libgphoto and libusb, as well as libtool. Has this been fixed with a newer revision of any of these libraries? |
in my case the issue turned out to be with the python bindings, and the maintainer of the python-gphoto2 repo helped and fixed the issue. HTH :) |
True, but the code left above still makes me believe that there could be a c-level problem, as it is also C++. You are correct, I am using the python bindings, but if there is a lower level issue in the c interface, then I would rather it be fixed there, then have to work around. |
there are likely smaller leaks in there. but currently they are hard to pinpoint :/ |
Totally understand, memory leaks are one of the most difficult to find :-) Perhaps then, another question. I am using an EOS type camera, and the python gphoto bound interface. What is the most proven method for initial bring-up of a camera? |
Hi, been a while since I posted here. I'm still having this problem (with the latest release of libgphto2). I'm not the most familiar with C/C++ debugging tools. If I compiled a debug build of libgphoto2 (and accompanying libraries) would it fill in those |
I tied the C level code ... when you press ctrl-c it will show a bigger leak as the data is not freed. I think we can close it, if you find other cases please report. |
Wait, I'm a little confused. Is it a problem with a third party library? |
I see it coming from the libtool library, it likely allocates some onetime things. Currently I see no recurring leaks. |
I'm using verison:
2.5.12-1
Here is my relevant code:
If I comment out that one like tagged with "memory leak," I no longer have any more memory leaks, but that kind of sucks since I can't query for connected cameras then. What's going on? Am I not using this library correct? Is the memory not being freed properly?
The text was updated successfully, but these errors were encountered: