Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d4d952f9 authored by Wonsik Kim's avatar Wonsik Kim
Browse files

aconfig: move `cache_` as a memeber

provider_ object relies on cache_ vector to be alive, but the order
of destruction between these objects at exit are not guaranteed.
This can lead to crash at the exit especially on ASAN build.
By putting cache_ as a member it is guaranteed that cache_ is not
destructed until provider_ is destructed.

Test: m ; m AconfigDemoActivity
Test: atest aconfig.test
Test: observe no crash on _hwasan build
Change-Id: If9e23e99c501bf8f06fcab003622948b9e730352
parent ca355c09
Loading
Loading
Loading
Loading
+3 −5
Original line number Original line Diff line number Diff line
@@ -151,12 +151,9 @@ mod tests {
#ifdef __cplusplus
#ifdef __cplusplus


#include <memory>
#include <memory>
#include <vector>


namespace com::android::aconfig::test {
namespace com::android::aconfig::test {


extern std::vector<int8_t> cache_;

class flag_provider_interface {
class flag_provider_interface {
public:
public:
    virtual ~flag_provider_interface() = default;
    virtual ~flag_provider_interface() = default;
@@ -359,6 +356,7 @@ void com_android_aconfig_test_reset_flags();
    const PROD_SOURCE_FILE_EXPECTED: &str = r#"
    const PROD_SOURCE_FILE_EXPECTED: &str = r#"
#include "com_android_aconfig_test.h"
#include "com_android_aconfig_test.h"
#include <server_configurable_flags/get_flags.h>
#include <server_configurable_flags/get_flags.h>
#include <vector>


namespace com::android::aconfig::test {
namespace com::android::aconfig::test {


@@ -407,9 +405,9 @@ namespace com::android::aconfig::test {
                return cache_[2];
                return cache_[2];
            }
            }


    };
    private:

        std::vector<int8_t> cache_ = std::vector<int8_t>(3, -1);
        std::vector<int8_t> cache_ = std::vector<int8_t>(3, -1);
    };


    std::unique_ptr<flag_provider_interface> provider_ =
    std::unique_ptr<flag_provider_interface> provider_ =
        std::make_unique<flag_provider>();
        std::make_unique<flag_provider>();
+0 −7
Original line number Original line Diff line number Diff line
@@ -18,16 +18,9 @@
#ifdef __cplusplus
#ifdef __cplusplus


#include <memory>
#include <memory>
{{ if not for_test- }}
#include <vector>
{{ -endif }}


namespace {cpp_namespace} \{
namespace {cpp_namespace} \{


{{ if not for_test- }}
extern std::vector<int8_t> cache_;
{{ -endif }}

class flag_provider_interface \{
class flag_provider_interface \{
public:
public:
    virtual ~flag_provider_interface() = default;
    virtual ~flag_provider_interface() = default;
+4 −3
Original line number Original line Diff line number Diff line
@@ -5,6 +5,8 @@
{{ if for_test }}
{{ if for_test }}
#include <unordered_map>
#include <unordered_map>
#include <string>
#include <string>
{{ -else- }}
#include <vector>
{{ endif }}
{{ endif }}


namespace {cpp_namespace} \{
namespace {cpp_namespace} \{
@@ -69,16 +71,15 @@ namespace {cpp_namespace} \{
            {{ -endif }}
            {{ -endif }}
        }
        }
        {{ endfor }}
        {{ endfor }}
    private:
        std::vector<int8_t> cache_ = std::vector<int8_t>({readwrite_count}, -1);
    };
    };


    std::vector<int8_t> cache_ = std::vector<int8_t>({readwrite_count}, -1);


{{ -endif }}
{{ -endif }}


std::unique_ptr<flag_provider_interface> provider_ =
std::unique_ptr<flag_provider_interface> provider_ =
    std::make_unique<flag_provider>();
    std::make_unique<flag_provider>();


}
}