Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

KPM: new[]/delete mismatch in vision::Image and leaked imageInfo in kpmDeleteHandle

Closed
#86 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp

Research direction

Start with the allocation in vision::Image::alloc (lib/SRC/KPM/FreakMatcher/framework/image.cpp, around line 149) and the destructor around line 118, which the shared_ptr deleter uses. Then read kpmDeleteHandle in lib/SRC/KPM/kpmHandle.cpp (lines 245-246) and kpmSetRefDataSet in lib/SRC/KPM/kpmMatching.cpp (line 243) to see how per-page imageInfo is freed on replacement. Done when an ASan build of webarkit_nft_core_test reports no alloc-dealloc-mismatch or leaks from these sites.

Written by the indexing model from the issue text.

Description

bug C/C++ code

Description

AddressSanitizer runs of the NFT core tests (webarkit/jsartoolkitNFT#683, webarkit_nft_core_test, 49 tests passing) found two pre-existing problems in the vendored KPM code. Neither is in the new core.

1. Allocation/deallocation mismatch in vision::Image

vision::Image::alloc (lib/SRC/KPM/FreakMatcher/framework/image.cpp:149) allocates with new unsigned char[...], and the buffer is owned by a std::shared_ptr<unsigned char> with the default deleter, which calls delete (not delete[]) in vision::Image::~Image (image.cpp:118). ASan aborts on alloc-dealloc-mismatch (operator new [] vs operator delete) in the first KPM test.

Fix: give the shared_ptr an array deleter (std::default_delete<unsigned char[]>()), or use std::shared_ptr<unsigned char[]> where the standard allows.

2. Leaked per-page imageInfo in kpmDeleteHandle

With ASAN_OPTIONS=alloc_dealloc_mismatch=0, LeakSanitizer reports 6732 bytes in 54 allocations. All 40 leak reports are allocated in kpmSetRefDataSet (lib/SRC/KPM/kpmMatching.cpp:243), which allocates each page's imageInfo array. kpmDeleteHandle (kpmHandle.cpp:245-246) frees pageInfo but not the per-page imageInfo; only a later kpmSetRefDataSet frees them when it replaces a set.

Fix: in kpmDeleteHandle, free each pageInfo[i].imageInfo before freeing pageInfo, mirroring what kpmSetRefDataSet does on replacement.

Notes

With these (and the thread_sub.c mutex issue), sanitizer runs exit non-zero even when the code under test is clean, so a sanitizer CI job would need suppressions until they are fixed.

Dominant language
C++
Stars
21
Forks
8
Avg merge
7h 30m
Merged PRs (30d)
25

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from webarkit/WebARKitLib

All issues in webarkit/WebARKitLib

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.