-
Notifications
You must be signed in to change notification settings - Fork 254
Fix memleak in signal package #1114
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
|
||
str := C.CString(string(data)) | ||
C.StatusServiceSignalEvent(str) | ||
C.free(unsafe.Pointer(str)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you verified that we don't cause any invalid memory reads on Android and iOS? For example, in Android, C.StatusServiceSignalEvent
we do if (javaJsonEvent != NULL) (*env)->DeleteLocalRef(env, javaJsonEvent);
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adambabik no, I haven't. But as I understand, CCstring always make a copy and responsibility to free its memory is on the caller.
javaJsonEvent
is a separate chunk of memory so it's ok that it is deleted there:
jstring javaJsonEvent = NULL;
if (jsonEvent != NULL) {
javaJsonEvent = (*env)->NewStringUTF(env, jsonEvent);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job!
I'll test it on a real server built from the branch before merging. |
We were investigating memory leak in a server instance of statusd, and here is a brief explanation of findings:
#1067 (comment)
TLDR:
a) we call signals even when running as a server
b) we historically never free memory allocated by
C.CString
.I believe this fix should stop memory from growing (or at least notable decrease growth).
Closes #1067