Skip to content

Commit 6697883

Browse files
authored
[tests, examples, refactoring]Remove unnecessary null pointer check in "tools/ref" and "examples" folders (#1221)
1 parent e5b594c commit 6697883

2 files changed

Lines changed: 11 additions & 21 deletions

File tree

examples/low-level-api/mix_paths_comp_decomp_w_dict_example.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@
2929
*/
3030
constexpr const uint32_t source_size = 2048U;
3131

32-
// Deallocate dictionary
33-
uint8_t destroy_dictionary(qpl_dictionary** dictionary_ptr) {
34-
if (*dictionary_ptr != nullptr) {
35-
free(*dictionary_ptr); //NOLINT(cppcoreguidelines-no-malloc)
36-
*dictionary_ptr = nullptr;
37-
}
38-
return 0;
39-
}
40-
4132
// Create dictionary with defined path
4233
uint8_t create_dictionary(qpl_path_t execution_path, std::vector<uint8_t>& source, qpl_dictionary** dictionary_ptr) {
4334
std::size_t dictionary_buffer_size = 0;
@@ -77,7 +68,11 @@ uint8_t create_dictionary(qpl_path_t execution_path, std::vector<uint8_t>& sourc
7768
qpl_build_dictionary(*dictionary_ptr, sw_compr_level, hw_compr_level, raw_dict_ptr, raw_dict_size);
7869
if (status != QPL_STS_OK) {
7970
std::cout << "An error " << status << " occurred during dictionary building.\n";
80-
destroy_dictionary(dictionary_ptr); // Clean up allocated memory
71+
72+
// Clean up allocated memory
73+
free(*dictionary_ptr); //NOLINT(cppcoreguidelines-no-malloc)
74+
*dictionary_ptr = nullptr;
75+
8176
return 1;
8277
}
8378

@@ -240,24 +235,24 @@ auto main(int argc, char** argv) -> int {
240235
const uint8_t comp_status = compression(execution_path, source, destination, dictionary_ptr);
241236
if (comp_status == QPL_STS_NOT_SUPPORTED_MODE_ERR) {
242237
// Free dictionary
243-
destroy_dictionary(&dictionary_ptr);
238+
free(dictionary_ptr); //NOLINT(cppcoreguidelines-no-malloc)
244239
return 0;
245240
} else if (comp_status != 0) {
246241
// Free dictionary
247-
destroy_dictionary(&dictionary_ptr);
242+
free(dictionary_ptr); //NOLINT(cppcoreguidelines-no-malloc)
248243
return comp_status;
249244
}
250245

251246
// Decompression with software_path and check if decompression failed
252247
const uint8_t decomp_status = sw_decompression(destination, reference, dictionary_ptr);
253248
if (decomp_status != 0) {
254249
// Free dictionary
255-
destroy_dictionary(&dictionary_ptr);
250+
free(dictionary_ptr); //NOLINT(cppcoreguidelines-no-malloc)
256251
return decomp_status;
257252
}
258253

259254
// Free dictionary
260-
destroy_dictionary(&dictionary_ptr);
255+
free(dictionary_ptr); //NOLINT(cppcoreguidelines-no-malloc)
261256

262257
// Compare source and reference
263258
for (size_t i = 0; i < source.size(); i++) {

tools/ref/include/own_ref_defs.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,8 @@ extern "C" {
143143
/**
144144
* @todo
145145
*/
146-
#define REF_FREE_PTR(ptr) \
147-
{ \
148-
if (NULL != (ptr)) { \
149-
free(ptr); \
150-
(ptr) = NULL; \
151-
} \
152-
}
146+
#define REF_FREE_PTR(ptr) \
147+
{ free(ptr); }
153148

154149
/**
155150
* @todo

0 commit comments

Comments
 (0)