Skip to content

Commit febedd0

Browse files
committed
Revert "simulate memory leak"
This reverts commit db2f4c0. simulate memory leak update lrs_options-to-html.py to parse 'mark_as_advanced' code review changes revert simulated memory leak simulate memory leak avoid error if output file missing Merge branch 'add_asan_to_CI' of https://github.com/gilpazintel/librealsense into add_asan_to_CI
2 parents 4a7a848 + daa73e9 commit febedd0

File tree

4 files changed

+50
-39
lines changed

4 files changed

+50
-39
lines changed

.github/workflows/static_analysis.yaml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,32 +128,32 @@ jobs:
128128
sed -i '/add_subdirectory(hello-realsense)/i add_subdirectory(memory-leaks-check)' "$CMAKE_FILE"
129129
fi
130130
131-
- name: Build Application with V4L Backend
131+
- name: Build Application
132132
run: |
133133
mkdir build
134134
cd build
135135
cmake .. -DBUILD_EXAMPLES=true
136136
make -j$(($(nproc)-1))
137137
138-
- name: Run Valgrind with V4L Backend
138+
- name: Run Valgrind
139139
run: |
140140
cd build
141-
valgrind --leak-check=yes --show-leak-kinds=all --track-origins=yes --log-file=valgrind-V4L-out.txt ./Release/mem-leak-test
141+
valgrind --leak-check=yes --show-leak-kinds=all --track-origins=yes --log-file=valgrind-out.txt ./Release/mem-leak-test
142142
continue-on-error: true
143143

144-
- name: Upload Valgrind V4L backend log
144+
- name: Upload Valgrind log
145145
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 #v4
146146
with:
147-
name: valgrind-V4L-log
148-
path: build/valgrind-V4L-out.txt
147+
name: valgrind-log
148+
path: build/valgrind-out.txt
149149

150-
- name: Check Valgrind V4L Results
150+
- name: Check Valgrind Results
151151
run: |
152-
if grep -q "ERROR SUMMARY: [^0]" build/valgrind-V4L-out.txt; then
153-
echo "Valgrind detected errors with V4L backend."
152+
if grep -q "ERROR SUMMARY: [^0]" build/valgrind-out.txt; then
153+
echo "Valgrind detected errors with backend."
154154
exit 1
155155
else
156-
echo "No errors detected by Valgrind with V4L backend."
156+
echo "No errors detected by Valgrind with backend."
157157
fi
158158
ASANCheck:
159159
name: ASAN Memory Leak Check
@@ -191,28 +191,28 @@ jobs:
191191
cmake .. -DBUILD_EXAMPLES=true -DBUILD_ASAN=true
192192
make -j$(($(nproc)-1))
193193
194-
- name: Run ASAN with V4L2 Backend
194+
- name: Run ASAN
195195
run: |
196196
cd build
197-
ASAN_OPTIONS=halt_on_error=0:detect_leaks=1:log_path=asan-V4L2-out.txt ./Release/mem-leak-test
197+
ASAN_OPTIONS=halt_on_error=0:detect_leaks=1:log_path=asan-out.txt ./Release/mem-leak-test
198198
continue-on-error: true
199199

200-
- name: Upload ASAN V4L2 backend log
200+
- name: Upload ASAN log
201201
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392
202202
with:
203-
name: asan-V4L2-log
204-
path: build/asan-V4L2-out.txt*
203+
name: asan-log
204+
path: build/asan-out.txt*
205205

206-
- name: Check ASAN V4L Results
206+
- name: Check ASAN Results
207207
run: |
208208
# Use a wildcard to match the file with any number appended
209-
ASAN_FILE=$(ls build/asan-V4L2-out.txt* 2>/dev/null)
209+
ASAN_FILE=$(ls build/asan-out.txt* 2>/dev/null || true)
210210
if [ -n "$ASAN_FILE" ]; then
211211
if grep -q "SUMMARY: AddressSanitizer:" "$ASAN_FILE"; then
212-
echo "ASAN detected memory leaks with V4L backend."
212+
echo "ASAN detected memory leaks."
213213
exit 1
214214
else
215-
echo "No memory leaks detected by ASAN with V4L backend."
215+
echo "No memory leaks detected by ASAN."
216216
fi
217217
else
218218
echo "No ASAN output file found. No errors detected."

CMake/lrs_options.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,5 @@ option(BUILD_WITH_DDS "Access camera devices through DDS topics (requires CMake
5555
option(BUILD_RS2_ALL "Build realsense2-all static bundle containing all realsense libraries (with BUILD_SHARED_LIBS=OFF)" ON)
5656
option(ENABLE_SECURITY_FLAGS "Enable additional compiler security flags to enhance the build's security" OFF)
5757
option(USE_EXTERNAL_LZ4 "Use externally build LZ4 library instead of building and using the in this repo provided version" OFF)
58+
option(BUILD_ASAN "Enable AddressSanitizer" OFF)
59+
mark_as_advanced(BUILD_ASAN)

CMakeLists.txt

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ cmake_minimum_required(VERSION 3.8)
44
set( LRS_TARGET realsense2 )
55
project( ${LRS_TARGET} LANGUAGES CXX C )
66

7-
# Define custom option for ASan
8-
option(BUILD_ASAN "Enable AddressSanitizer" OFF)
9-
10-
# Conditionally apply ASan flags
11-
if(BUILD_ASAN)
12-
message(STATUS "AddressSanitizer is enabled")
13-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
14-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -g")
15-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
16-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
17-
endif()
18-
197
# Allow librealsense2 and all of the nested project to include the main repo folder
208
set(REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
219
include_directories(${REPO_ROOT})
@@ -63,6 +51,11 @@ global_set_flags()
6351
add_library(${LRS_TARGET})
6452
# Apply ASan flags if enabled
6553
if(BUILD_ASAN)
54+
message(STATUS "AddressSanitizer is enabled")
55+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -g")
56+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -g")
57+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
58+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
6659
target_compile_options(${LRS_TARGET} PRIVATE -fsanitize=address -g)
6760
endif()
6861

scripts/lrs_options-to-html.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22

3-
43
def add_style(option, val):
54
# colorize ON and OFF keywords
65
val = val.replace('ON', '<span style="color: #4CAF50;">ON</span>')
@@ -22,25 +21,32 @@ def add_style(option, val):
2221

2322
return val
2423

25-
2624
def add_row(option, description, value):
25+
advanced = "YES" if option in advanced_options else "NO"
2726
if option in table_rows:
2827
# update value if option exists
2928
table_rows[option][2] = value
29+
table_rows[option][3] = advanced
3030
else:
3131
# add to table new option
32-
table_rows[option] = [option, description, value]
32+
table_rows[option] = [option, description, value, advanced]
3333

34+
def update_advanced_status():
35+
for option in table_rows:
36+
if option in advanced_options:
37+
table_rows[option][3] = "YES" # Update advanced status to YES
3438

3539
with open('CMake/lrs_options.cmake', 'r') as file:
3640
lines = file.readlines()
3741

3842
table_rows = {}
43+
advanced_options = set()
3944
in_cond = False
4045
in_elseif = False
4146
in_else = False
4247
current_condition = None
4348
current_comment = ""
49+
last_option = None # Track the last option processed
4450

4551
for i, line in enumerate(lines):
4652
if line.strip().startswith(('option(', 'set(')):
@@ -71,6 +77,7 @@ def add_row(option, description, value):
7177

7278
value = add_style(option, value)
7379
add_row(option, description, value)
80+
last_option = option # Update the last option processed
7481
elif line.startswith('if'):
7582
parts = line.strip().split('(', 1)
7683
condition = parts[1][:-1] # remove last ")" - part of the 'if'
@@ -94,19 +101,28 @@ def add_row(option, description, value):
94101
continue # ignore internal comments
95102
elif line.startswith('#'):
96103
current_comment += line.strip('# \n')
104+
elif line.startswith('mark_as_advanced'):
105+
parts = line.strip().split('(')
106+
option = parts[1].strip(')') # extract the option name
107+
advanced_options.add(option) # add to advanced options set
108+
if last_option: # Check if last_option is set
109+
advanced_options.add(last_option) # Mark the last option as advanced
97110
elif line.strip():
98111
# if we reach a line that doesn't match the pattern, throw an error as it's not handled (shouldn't happen)
99112
raise Exception(f"{i, line} not handled")
100113

114+
# Update advanced status for all options after processing the file
115+
update_advanced_status()
101116

102117
def format_dict_values():
103118
return ''.join(
104119
f'\n <tr>'
105120
f'\n\t<td>\n\t <b><code>{option}</code></b>'f'\n\t</td>'
106121
f'\n\t<td>\n\t {description}\n\t</td>'
107122
f'\n\t<td>\n\t {value}\n\t</td>'
123+
f'\n\t<td>\n\t <span style="color: {"#4CAF50" if advanced == "YES" else "#E74C3C"};">{advanced}</span>\n\t</td>'
108124
f'\n </tr>'
109-
for option, description, value in table_rows.values())
125+
for option, description, value, advanced in table_rows.values())
110126

111127
def get_sdk_version():
112128
if len(sys.argv) > 1:
@@ -117,7 +133,6 @@ def get_sdk_version():
117133
# if no parameter provided - no version number will be included
118134
return ""
119135

120-
121136
html = f'''<!DOCTYPE html>
122137
<html>
123138
<head>
@@ -131,9 +146,10 @@ def get_sdk_version():
131146
<h2>{get_sdk_version()}</h2>
132147
<table>
133148
<tr>
134-
<th style="width: 30%">Option</th>
135-
<th style="width: 55%">Description</th>
149+
<th style="width: 25%">Option</th>
150+
<th style="width: 45%">Description</th>
136151
<th style="width: 15%">Default</th>
152+
<th style="width: 15%">Advanced</th>
137153
</tr>{format_dict_values()}
138154
</table>
139155
</div>
@@ -143,4 +159,4 @@ def get_sdk_version():
143159

144160
with open('doc/build-flags.html', 'w') as file:
145161
file.write(html)
146-
print("build-flags.html generated")
162+
print("build-flags.html generated")

0 commit comments

Comments
 (0)