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

Commit 62a752fd authored by Chris Manton's avatar Chris Manton
Browse files

legacy: Move OsiObject into osi_allocation

Also add const interface
Group memory allocations together

Bug: 202068782
Test: cert/run
Tag: #refactor

Change-Id: I9c73cf462ba8a3a221da4e2b17ecf9000be77b16
parent ec1aa511
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -271,24 +271,6 @@ static bool event_already_registered_in_le_scanning_manager(
  return false;
}

class OsiObject {
 public:
  OsiObject(void* ptr) : ptr_(ptr) {}
  ~OsiObject() {
    if (ptr_ != nullptr) {
      osi_free(ptr_);
    }
  }
  void* Release() {
    void* ptr = ptr_;
    ptr_ = nullptr;
    return ptr;
  }

 private:
  void* ptr_;
};

}  // namespace

namespace cpp {
+11 −0
Original line number Diff line number Diff line
@@ -51,3 +51,14 @@ void osi_free_and_reset(void** p_ptr);
// descriptor.
// The information is in user-readable text format. The |fd| must be valid.
void osi_allocator_debug_dump(int fd);

class OsiObject {
 public:
  OsiObject(void* ptr);
  OsiObject(const void* ptr);
  ~OsiObject();
  void* Release();

 private:
  void* ptr_;
};
+16 −0
Original line number Diff line number Diff line
@@ -83,3 +83,19 @@ void osi_free_and_reset(void** p_ptr) {
const allocator_t allocator_calloc = {osi_calloc, osi_free};

const allocator_t allocator_malloc = {osi_malloc, osi_free};

OsiObject::OsiObject(void* ptr) : ptr_(ptr) {}

OsiObject::OsiObject(const void* ptr) : ptr_(const_cast<void*>(ptr)) {}

OsiObject::~OsiObject() {
  if (ptr_ != nullptr) {
    osi_free(ptr_);
  }
}

void* OsiObject::Release() {
  void* ptr = ptr_;
  ptr_ = nullptr;
  return ptr;
}