Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Do not use defined inside macros #193

Closed
wants to merge 1 commit into from
Closed

Do not use defined inside macros #193

wants to merge 1 commit into from

Conversation

michaelkuhn
Copy link
Contributor

This causes warnings on newer GCC and Clang versions that enable -Wexpansion-to-defined by default.

This causes warnings on newer GCC and Clang versions that enable
-Wexpansion-to-defined by default.
@bjori
Copy link
Contributor

bjori commented Jun 26, 2017

I realize this code is a bit weird, but I wonder how you noticed.
Is this a warning level in some compiler? If so, which?

@bjori
Copy link
Contributor

bjori commented Jun 26, 2017

Heh. I've lost the ability to read the summary. Sorry :)

@bjori
Copy link
Contributor

bjori commented Jun 26, 2017

Cross referencing with https://jira.mongodb.org/browse/CDRIVER-2197

@sotex
Copy link

sotex commented Jun 28, 2017

Memory leak problem
Sorry,I did not find the entrance to the Issue.

The code is as follows

#include <mcheck.h>
#include <bson.h>
#include <stdio.h>

int main()
{
	setenv("MALLOC_TRACE", "mtrace.log", 1);
	mtrace();

	bson_t* bson = bson_new();
	bson_append_utf8(bson,"k",1,"1234",4);
	
	char* str = bson_as_json(bson,NULL);
	puts(str);
	bson_free(str);
	bson_destroy(bson);

	muntrace();
	return 0;
}

compile and run....
Use mtrace to view the mtrace.log file.

> mtrace mtrace.log                                                 

Memory not freed:
-----------------
           Address     Size     Caller
0x0000000001fdd620    0x400  at 0x7f5adcd7be6c

I looked at the implementation of the bson_as_json function, did not find the problem.
As long as the bson_strdup is called, there will be a problem.

        char* str = bson_strdup("xxxxx");  //bson_as_json(bson,NULL);
	puts(str);
	bson_free(str);

environment

OS: Linux o-s 4.10.13-1-ARCH 64bit
CC: gcc 6.3.1
libbson:1.6.3

@bjori
Copy link
Contributor

bjori commented Jul 18, 2017

Merged as b519654

Thanks!

@bjori bjori closed this Jul 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants