Memory leak reported for long string debug variables in ULTs

This commit eliminates ULTs memory leaks reported for string debug variables
exceeding small string optimization size by calling shrink_to_fit() method
on string debug variables in DebugManagerStateRestore destructor.

Change-Id: I304c5c5c23c80f01fdf13f38cea5b4eceb18a94f
Signed-off-by: Pawel Wilma <pawel.wilma@intel.com>
This commit is contained in:
Pawel Wilma
2018-11-23 09:43:06 +01:00
committed by sys_ocldev
parent 4f28f7a647
commit 86ecd1a4b8
3 changed files with 33 additions and 28 deletions

View File

@@ -49,17 +49,20 @@ class SettingsReader;
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) \
struct DebugVar##variableName \
{ \
DebugVar##variableName() { \
value = (dataType)defaultValue; \
} \
dataType get() const { \
return value; \
} \
void set(dataType data) { \
value = data; \
} \
private: \
dataType value; \
DebugVar##variableName() { \
value = (dataType)defaultValue; \
} \
dataType get() const { \
return value; \
} \
void set(dataType data) { \
value = data; \
} \
dataType& getRef() { \
return value; \
} \
private: \
dataType value; \
};
#include "debug_variables.inl"

View File

@@ -1,23 +1,8 @@
/*
* Copyright (c) 2017, Intel Corporation
* Copyright (C) 2017-2018 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
* SPDX-License-Identifier: MIT
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
@@ -35,9 +20,20 @@ class DebugManagerStateRestore {
~DebugManagerStateRestore() {
DebugManager.flags = debugVarSnapshot;
DebugManager.injectFcn = injectFcnSnapshot;
#undef DECLARE_DEBUG_VARIABLE
#define DECLARE_DEBUG_VARIABLE(dataType, variableName, defaultValue, description) shrink(DebugManager.flags.variableName.getRef());
#include "debug_variables.inl"
#undef DECLARE_DEBUG_VARIABLE
}
DebugSettingsManager<globalDebugFunctionalityLevel>::DebugVariables debugVarSnapshot;
void *injectFcnSnapshot = nullptr;
protected:
void shrink(std::string &flag) {
flag.shrink_to_fit();
}
void shrink(int32_t &flag) {}
void shrink(bool &flag) {}
};
class RegistryReaderMock : public SettingsReader {

View File

@@ -10,6 +10,7 @@
#include "gmock/gmock.h"
#include "runtime/helpers/file_io.h"
#include "runtime/helpers/string_helpers.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "runtime/os_interface/debug_settings_manager.h"
#include "runtime/utilities/directory.h"
#include "unit_tests/mocks/mock_kernel.h"
@@ -941,3 +942,8 @@ TEST(DebugSettingsManager, givenTwoPossibleVariantsOfHardwareInfoOverrideStringT
debugManager.getHardwareInfoOverride(hwInfoConfig);
EXPECT_EQ(str1, hwInfoConfig);
}
TEST(DebugSettingsManager, givenStringDebugVariableWhenLongValueExeedingSmallStringOptimizationIsAssignedThenMemoryLeakIsNotReported) {
DebugManagerStateRestore debugManagerStateRestore;
DebugManager.flags.AUBDumpCaptureFileName.set("ThisIsVeryLongStringValueThatExceedSizeSpecifiedBySmallStringOptimizationAndCausesInternalStringBufferResize");
}