Skip to content

Commit 29116a7

Browse files
committed
Merge pull request #143 from vadz/asio-mem-leak-fix
Work around SSL compression methods memory leak in ASIO
2 parents 3070ca2 + 12619af commit 29116a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+2014
-1778
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,6 @@ Intermediate/
6363
**/packages/*
6464
# except build/, which is used as an MSBuild target.
6565
!**/packages/build/
66-
66+
.vs/
67+
# Ignore cmake building directories
68+
build.*/

Release/CMakeLists.txt

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
22
cmake_minimum_required(VERSION 2.6)
3-
project(casablanca)
3+
project(cpprest)
44

55
enable_testing()
66

77
set(WARNINGS)
88
set(ANDROID_STL_FLAGS)
99

10+
option(WERROR "Threat Warnings as Errors" ON)
11+
option(BUILD_TESTS "Build tests." ON)
12+
option(CPPREST_EXCLUDE_WEBSOCKETS "Exclude websockets functionality." OFF)
13+
1014
# Platform (not compiler) specific settings
1115
if(IOS)
1216
set(IOS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../Build_iOS")
@@ -25,7 +29,6 @@ if(IOS)
2529

2630
set(BUILD_SHARED_LIBS OFF)
2731
set(BUILD_SAMPLES OFF)
28-
option(BUILD_TESTS "Build tests." ON)
2932
elseif(ANDROID)
3033
set(Boost_COMPILER "-clang")
3134
set(Boost_USE_STATIC_LIBS ON)
@@ -71,9 +74,8 @@ elseif(ANDROID)
7174

7275
option(BUILD_SHARED_LIBS "Build shared Libraries." OFF)
7376
set(BUILD_SAMPLES OFF)
74-
option(BUILD_TESTS "Build tests." ON)
7577
elseif(UNIX) # This includes OSX
76-
find_package(Boost REQUIRED COMPONENTS random chrono system thread regex filesystem)
78+
find_package(Boost 1.54 REQUIRED COMPONENTS random chrono system thread regex filesystem)
7779
find_package(Threads REQUIRED)
7880
if(APPLE AND NOT OPENSSL_ROOT_DIR)
7981
# Prefer a homebrew version of OpenSSL over the one in /usr/lib
@@ -86,7 +88,6 @@ elseif(UNIX) # This includes OSX
8688
find_package(OpenSSL 1.0.0 REQUIRED)
8789

8890
option(BUILD_SHARED_LIBS "Build shared Libraries." ON)
89-
option(BUILD_TESTS "Build tests." ON)
9091
option(BUILD_SAMPLES "Build samples." ON)
9192
option(CASA_INSTALL_HEADERS "Install header files." ON)
9293
if(CASA_INSTALL_HEADERS)
@@ -99,9 +100,7 @@ elseif(UNIX) # This includes OSX
99100
endif()
100101
elseif(WIN32)
101102
option(BUILD_SHARED_LIBS "Build shared Libraries." ON)
102-
option(BUILD_TESTS "Build tests." ON)
103103
option(BUILD_SAMPLES "Build samples." ON)
104-
option(CPPREST_EXCLUDE_WEBSOCKETS "Exclude websockets functionality." OFF)
105104
option(Boost_USE_STATIC_LIBS ON)
106105

107106
add_definitions(-DUNICODE -D_UNICODE)
@@ -115,11 +114,31 @@ elseif(WIN32)
115114
endif()
116115
add_definitions(${Casablanca_DEFINITIONS} -D_WINSOCK_DEPRECATED_NO_WARNINGS -DWIN32)
117116

118-
if (CPPREST_EXCLUDE_WEBSOCKETS)
119-
add_definitions(-DCPPREST_EXCLUDE_WEBSOCKETS=1)
120-
else()
121-
find_package(Boost 1.55 REQUIRED COMPONENTS random system thread filesystem chrono atomic)
122-
find_package(OpenSSL 1.0 REQUIRED)
117+
if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
118+
set(NUGET_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../packages")
119+
set(PACKAGE_PATHS)
120+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost.1.58.0.0/")
121+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost_system-vc140.1.58.0-vs140rc/")
122+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost_date_time-vc140.1.58.0-vs140rc/")
123+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost_regex-vc140.1.58.0-vs140rc/")
124+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/openssl.v140.windesktop.msvcstl.static.rt-dyn.x64.1.0.2.1/")
125+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/zlib.v140.windesktop.msvcstl.static.rt-dyn.1.2.8.8/")
126+
127+
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
128+
find_library(Boost_SYSTEM_LIBRARY libboost_system-vc140-mt-gd-1_58.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/address-model-64/lib)
129+
find_library(Boost_DATE_TIME_LIBRARY libboost_date_time-vc140-mt-gd-1_58.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/address-model-64/lib)
130+
find_library(Boost_REGEX_LIBRARY libboost_regex-vc140-mt-gd-1_58.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/address-model-64/lib)
131+
set(Boost_LIBRARIES ${Boost_REGEX_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY})
132+
133+
find_library(OpenSSL_libeay_LIBRARY libeay32.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/debug)
134+
find_library(OpenSSL_ssleay_LIBRARY ssleay32.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/debug)
135+
find_library(ZLIB_LIBRARY zlibstaticd.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/debug)
136+
set(OPENSSL_LIBRARIES ${OpenSSL_ssleay_LIBRARY} ${OpenSSL_libeay_LIBRARY} ${ZLIB_LIBRARY})
137+
138+
set(OPENSSL_INCLUDE_DIR "${NUGET_PATH}/openssl.v140.windesktop.msvcstl.static.rt-dyn.x64.1.0.2.1/build/native/include")
139+
endif()
140+
141+
set(Boost_INCLUDE_DIR "${NUGET_PATH}/boost.1.58.0.0/lib/native/include")
123142
endif()
124143
else()
125144
message(FATAL_ERROR "-- Unsupported Build Platform.")
@@ -158,11 +177,20 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
158177
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
159178
message("-- Setting msvc options")
160179
set(WARNINGS)
180+
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4264")
181+
add_compile_options(/bigobj)
182+
if (WINDOWS_STORE OR WINDOWS_PHONE)
183+
add_compile_options(/ZW)
184+
endif()
161185
else()
162186
message("-- Unknown compiler, success is doubtful.")
163187
message("CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")
164188
endif()
165189

190+
if (CPPREST_EXCLUDE_WEBSOCKETS)
191+
add_definitions(-DCPPREST_EXCLUDE_WEBSOCKETS=1)
192+
endif()
193+
166194
# Reconfigure final output directory
167195
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
168196
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
@@ -188,16 +216,8 @@ else()
188216
set(Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
189217
endif()
190218

191-
set(Casablanca_LIBRARY ${LIB}cpprest)
192-
set(Casablanca_LIBRARIES ${Casablanca_LIBRARY}
193-
${Boost_FILESYSTEM_LIBRARY}
194-
${Boost_SYSTEM_LIBRARY}
195-
${Boost_THREAD_LIBRARY}
196-
${Boost_ATOMIC_LIBRARY}
197-
${Boost_CHRONO_LIBRARY}
198-
${Boost_RANDOM_LIBRARY}
199-
${Boost_REGEX_LIBRARY}
200-
${Boost_FRAMEWORK})
219+
set(Casablanca_LIBRARY cpprest)
220+
set(Casablanca_LIBRARIES cpprest ${Boost_LIBRARIES})
201221

202222
# Everything in the project needs access to the casablanca include directories
203223
include_directories(${Casablanca_INCLUDE_DIRS})
@@ -208,16 +228,16 @@ function(add_casablanca_test NAME SOURCES_VAR)
208228
message("-- Added test library ${NAME}")
209229
if (NOT TEST_LIBRARY_TARGET_TYPE STREQUAL "OBJECT")
210230
target_link_libraries(${NAME}
211-
${LIB}httptest_utilities
212-
${LIB}common_utilities
213-
${LIB}unittestpp
231+
httptest_utilities
232+
common_utilities
233+
unittestpp
214234
${Casablanca_LIBRARIES}
215235
${ANDROID_STL_FLAGS}
216236
)
217237
if (BUILD_SHARED_LIBS)
218238
add_test(NAME ${NAME}
219239
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
220-
COMMAND test_runner lib${NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
240+
COMMAND test_runner $<TARGET_FILE_NAME:${NAME}>
221241
)
222242
endif()
223243
endif()

Release/include/cpprest/containerstream.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,8 @@ namespace Concurrency { namespace streams {
439439

440440
size_t newPos = m_current_position + read_size;
441441

442-
auto readBegin = begin(m_data) + m_current_position;
443-
auto readEnd = begin(m_data) + newPos;
442+
auto readBegin = std::begin(m_data) + m_current_position;
443+
auto readEnd = std::begin(m_data) + newPos;
444444

445445
#ifdef _WIN32
446446
// Avoid warning C4996: Use checked iterators under SECURE_SCL
@@ -470,7 +470,7 @@ namespace Concurrency { namespace streams {
470470
resize_for_write(newSize);
471471

472472
// Copy the data
473-
std::copy(ptr, ptr + count, begin(m_data) + m_current_position);
473+
std::copy(ptr, ptr + count, std::begin(m_data) + m_current_position);
474474

475475
// Update write head and satisfy pending reads if any
476476
update_current_position(newSize);

0 commit comments

Comments
 (0)