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

Commit c4142d91 authored by Ryan Mitchell's avatar Ryan Mitchell
Browse files

libafw: Use std::free explicitly for overlays

Currently we rely on libc to call std::free on the malloced pointer to
the overlay table entry. Rather than relying on the libc implementation
to call std::free instead of trying to delete the pointer as if it was
created using "new", explicitly pass std::free as the deleter to the
data held by the std::shared_ptr.

Bug: 159562360
Test: Observed no heap growth while looping infinitely and retrieving
      a string resource overlaid using an inline xml value
Change-Id: I9a2ebaf9a993ad9c44fab8f052430c8142d4347d
parent bb2d9a52
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ IdmapResMap::Result IdmapResMap::Lookup(uint32_t target_res_id) const {
  table_value->dataType = entry->type;
  table_value->data = entry->value;

  return Result(ResTable_entry_handle::managed(table_entry));
  return Result(ResTable_entry_handle::managed(table_entry, [](auto p) { free(p); }));
}

static bool is_word_aligned(const void* data) {
+2 −2
Original line number Diff line number Diff line
@@ -1601,8 +1601,8 @@ class ResTable_entry_handle {
      entry_ = handle.entry_;
    }

    inline static ResTable_entry_handle managed(ResTable_entry* entry)  {
      return ResTable_entry_handle(std::shared_ptr<const ResTable_entry>(entry));
    inline static ResTable_entry_handle managed(ResTable_entry* entry, void (*deleter)(void *)) {
      return ResTable_entry_handle(std::shared_ptr<const ResTable_entry>(entry, deleter));
    }

    inline static ResTable_entry_handle unmanaged(const ResTable_entry* entry)  {