Crash in windows when creating uri::uri

To preface, my code has been working in linux for a while. My next task is to get our program working on windows now.

I have installed manually compiled mongoc (v1.23.5) and mongocxx (v3.7.2), and gotten it building. When i run in debug mode, it works perfectly, but when i run my executable in release mode, it crashes when creating a uri.

in the mongcxx lib, it crashes here:

    if (_impl->uri_t == nullptr) {
        throw logic_error{error_code::k_invalid_uri, error.message};
    }

this is part of:

uri::uri(bsoncxx::string::view_or_value uri_string) {
    bson_error_t error;

    _impl = stdx::make_unique<impl>(
        libmongoc::uri_new_with_error(uri_string.terminated().data(), &error));

    if (_impl->uri_t == nullptr) {
        throw logic_error{error_code::k_invalid_uri, error.message};
    }
}

error.message is ‘invalid utf-8 in uri’

I have absolutely no idea why this is throwing an invalid uri error when it works perfectly fine in debug mode (and on linux). I have verified via debug that the string going into the function is good.

Any help would be appreciated.

After more research, it seems similar to https://www.mongodb.com/community/forums/t/mongo-cxx-driver-r3-6-0-using-std-string-on-mongocxx-uri-leading-to-crash/9582
but not quite the same, and still crashes after setting /MD

Hi @Ian_Haber ,

I suspect this issue may instead be caused by the use of incompatible build configurations for the library vs. the test application. The build configuration for a Windows application must be consistent with the build configuration of all the libraries being linked against. To compile and link the test application using the Release configuration, it must link against the library which was also built using the Release configuration.

Weird string crashes are the canonical symptom of such misconfigurations.

i built all of the mongo libraries in release. interestingly enough, the debug mode works, but release doesnt.

Okay, i’ve found the issue and fixed it.

For future reference, building with visual studio seems to ignore -DCMAKE_BUILD_TYPE when building mongoc-driver and mongocxx-driver. you have to specify --config RelWithDebInfo as well when building them.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.