Details
- Reviewers
- None
- Bugzilla Bug ID
- 1854965
Diff Detail
- Repository
- rMOZILLACENTRAL mozilla-central
- Branch
- default
Event Timeline
Code Review Summarization
1. Intent
The changes aim to apply Mozilla-specific patches to the libogg library during its update to version 1.3.6. Specifically, these modifications enable custom memory allocation functions to be used instead of the standard C library memory functions (malloc, calloc, realloc, free). This is necessary to accommodate Firefox's memory reporting infrastructure, which requires tracking and monitoring memory allocations made by third-party libraries within the browser environment.
2. Solution
The solution replaces the original static memory allocation macros with a dynamic system based on function pointers:
In os_types.h: The original preprocessor definitions that directly mapped memory allocation functions to standard library functions are removed. Instead, type definitions for custom memory allocation function signatures are introduced, along with extern declarations for global function pointers. The original macro names are redefined to point to these function pointers rather than directly to the standard library functions. C++ compatibility is ensured through extern C linkage guards.
In ogg_alloc.c: A new source file is created that initializes the global function pointers with the standard library memory functions as defaults. It also implements a setter function that allows external code to override these function pointers at runtime with custom implementations.
In ogg.h: The public API is extended by adding a declaration for the new setter function, making it available to library users who need to configure custom memory allocation handlers.
This approach maintains backward compatibility while enabling Firefox to inject its own memory tracking implementations at runtime.
<budget:token_budget>
Tokens used: 1422
Percentage of budget used: 0.71%
</budget:token_budget>
| media/libogg/src/ogg_alloc.c | ||
|---|---|---|
| 27 | Add NULL checks for all function pointer parameters. If NULL is passed, subsequent memory allocations will crash. | |
| 27 | The assignments create data races if called concurrently with memory allocations or from multiple threads. Add synchronization or document that this function must only be called during single-threaded initialization before any ogg library usage. | |