uber / uber/h3-java

OOM handling in C

Open
#10 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
333
Forks
68
PR merge metrics
No merged PRs in 30d

Description

The h3 C library does not handle the case of malloc/calloc/realloc returning NULL in a robust manner. If assertions are enabled, the library crashes, otherwise it will use the NULL pointer leading to undefined behavior. While I understand the convenience of this design in the C library, not propagating OOM errors up the stack means binding code like this is not reliable: https://github.com/uber/h3-java/blob/ed818d3d07c005576c0f96490015f388992b6df8/src/main/c/h3-java/src/jniapi.c#L44 Users are likely to see a sudden fatal crash in the Java process and may not see any hint to the C assertion. Practically, consider using return codes to handle OOM up the stack for your C functions so you can handle them probably here.

Contributor guide

Open the contributing guide

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.

Research direction

Start with the JNI binding entry point mentioned at src/main/c/h3-java/src/jniapi.c#L44, then trace the H3 C functions it calls and their malloc/calloc/realloc handling. Done means out-of-memory failures are propagated through the relevant C and Java binding layers instead of causing assertions or NULL-pointer undefined behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, java
Domain
api, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.