Skip to content
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

Fix possible memory leak and remove superfluous NULL checks before free() #198

Merged
merged 2 commits into from Nov 28, 2015
Merged

Fix possible memory leak and remove superfluous NULL checks before free() #198

merged 2 commits into from Nov 28, 2015

Conversation

anmolsarma
Copy link
Contributor

No description provided.

@hawicz
Copy link
Member

hawicz commented Nov 15, 2015

This change is either incomplete, or wrong. If setlocale(LC_NUMERIC, NULL) can never return NULL, then the use of tmplocale is superfluous and can be removed. On the other hand, if that can return NULL, then it's possible for oldlocale to be NULL, so the NULL checks are required.

@anmolsarma
Copy link
Contributor Author

@hawicz If the pointer passed to free() is NULL, no action occurs. It is not necessary to check if a pointer is NULL before calling free() on it.

@hawicz
Copy link
Member

hawicz commented Nov 28, 2015

Sory, but json-c is used on many different systems and on some it is necessary to check for null. Just because you can get away with it on your particular OS with your particular malloc implementation is not a reason to break it elsewhere.

@rgerhards
Copy link
Contributor

@hawicz just out of curiosity: which currently existing system is so broken that it is necessary to check for NULL when calling free? It's long standardized that this is a no-op, see http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1124.pdf section 7.20.3.2.

@hawicz
Copy link
Member

hawicz commented Nov 28, 2015

hmm... it seems that I'm wrong about calling free(NULL) being a problem. It still feels wrong to me, but perhaps that just me getting old and crufty. In some ways I like the fact that a check for null helps imply what's values are expected to be present, but now not enough to block this change.

hawicz added a commit that referenced this pull request Nov 28, 2015
Fix possible memory leak and remove superfluous NULL checks before free()
@hawicz hawicz merged commit 5a6a378 into json-c:master Nov 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants