Commit 1f7fdb8
authored
Fix MessageId::getDataAsString() crashed with MSVC debug config (#108)
Fixes #107
### Motivation
The `MessageId::getDataAsString()` API returns a `std::string` to the
application side. In most cases it's not an issue. However, when
building Windows DLLs with `LINK_STATIC=ON`, the library will be
built with `/MTd` or `/MT` option to link 3rd party dependencies
statically. In this case, the DLL and the application have different C
runtime libraries that allocate or deallocate memory. The returned
`std::string` object is allocated inside the DLL, while it will be
destroyed in the application. The destruction could crash because the
application C runtime cannot find the heap address from the C runtime in
DLL.
### Modifications
For MSVC debug build, change the API to return a const reference to
`std::string`. Then the original `std::string` object will be
deallocated inside the DLL.1 parent 74ef1a0 commit 1f7fdb8
2 files changed
+15
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
93 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
94 | 100 | | |
| 101 | + | |
95 | 102 | | |
96 | 103 | | |
97 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
57 | 64 | | |
| 65 | + | |
58 | 66 | | |
59 | 67 | | |
60 | 68 | | |
| |||
0 commit comments