-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ZMS memory alocation error when runStream is called. #1153
Comments
This code doesn't look right to me. The code appear to use sizeof to return the size of the malloc but it is not how it works. It actually return the size of "type" of swap_path which is the size of the C pointer. In this case, it will be 8 (as running in x86_64) I think it will be much clean to define a "constant" for the 15. and reuse on other part of the code. so the snprintf will be underflow which and size_t is unsigned. So it will create a huge number. I don't know how big is the your monitorID. I don't know whether it could be more than 6 digits and overflow swap_path and then corrupt the heap. (which could explain the later new abort) |
if ( checkSwapPath( swap_path, true ) ) { The connkey in this one could overflow the buffer so the previous monitorID probably ok. |
Thanks for the feedback. I'll take a look those lines of code. I hadn't considered the previous memory allocation being the actual culprit. |
instead of sizeof(swap_path)-swap_path_length, couldn't we just write 15? |
Boom. That was it. It took me a while to understand this, but once I replaced Will continue to verify the issue is fixed in all my environments, but I'm confident it will. And to think I've been staring at this and scratching my head literally for 2 months now. |
👍 |
Finally getting around to documenting this.
I have been chasing this error for well over a month now, and I'm out of ideas.
I'm testing in several virtual environments:
Development build of ZoneMinder 1.28.108
2GB ram
One Airlink 747W vga, mjpeg ip camera
One Foscam 9821 720p, h264 ip camera
CentOS or Fedora
Problem:
On recent development builds, ZMS started crashing when attempting to live stream for one of the named cameras, but never both at the same time. Event playback works fine. In one test environment the crash appears when using the Airlink, but in another environment the crash appears when using the Foscam camera. This happens in my CentOS 6 and CentOS 7 environments, but I have not been able to duplicate this in a Fedora environment. If I roll back to zoneminder 1.28.1, everything works.
Now get this. If I turn Debug on, under options, both cameras stream fine! Hello, race condition?
This is what appears in the zoneminder log:
From the error text, one can see that the crash is happening around when ZMS calls runStream. By strategic placement of Info statements, I have confirmed that the crash happens when the "new" operator is called to create a temporary image buffer:
https://github.com/ZoneMinder/ZoneMinder/blob/master/src/zm_monitor.cpp#L4224
At this point in the code, temp_image_buffer_count has the default value of 1000. Lowering this value does not help. Also, giving the virtual machine more memory does not help either.
Recall this line works fine for one camera, but not the other.
I have tried using valgrind to tickle out more information by changing ZM_PATH_ZMS to point to a script valgrind.sh which looks like this:
ZoneMinder debug symbols have been loaded.
The full Valgrind output can be found here:
https://gist.github.com/knnniggett/73c571caf626cccada53
The last part of the Valgrind log appears to be the most interesting:
I'm currently trying to understand this information, and would appreciate the help if anyone has any ideas.
The text was updated successfully, but these errors were encountered: