Skip to content

Commit 1f533bd

Browse files
authored
Missing comments from #15083. NFC. (#15092)
Not sure how I missed adding these.
1 parent 34ff848 commit 1f533bd

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/library.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2644,8 +2644,10 @@ LibraryManager.library = {
26442644
{{{ makeEval('return eval(UTF8ToString(ptr))|0;') }}}
26452645
},
26462646

2647-
emscripten_run_script_string__sig: 'ii',
2647+
// We use builtin_malloc and builtin_free here because otherwise lsan will
2648+
// report the last returned string as a leak.
26482649
emscripten_run_script_string__deps: ['emscripten_builtin_malloc', 'emscripten_builtin_free'],
2650+
emscripten_run_script_string__sig: 'ii',
26492651
emscripten_run_script_string: function(ptr) {
26502652
{{{ makeEval("var s = eval(UTF8ToString(ptr));") }}}
26512653
if (s == null) {
@@ -2930,6 +2932,8 @@ LibraryManager.library = {
29302932
_emscripten_log_js(flags, str);
29312933
},
29322934

2935+
// We never free the return values of this function so we need to allocate
2936+
// using builtin_malloc to avoid LSan reporting these as leaks.
29332937
emscripten_get_compiler_setting__deps: ['emscripten_builtin_malloc'],
29342938
emscripten_get_compiler_setting: function(name) {
29352939
#if RETAIN_COMPILER_SETTINGS

system/lib/libc/musl/src/env/__environ.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
#include "libc.h"
22

3-
#ifdef __EMSCRIPTEN__
4-
#include <stdlib.h>
5-
#include <wasi/api.h>
6-
#include <emscripten/emmalloc.h>
7-
#endif
8-
93
char **__environ = 0;
104
weak_alias(__environ, ___environ);
115
weak_alias(__environ, _environ);
126
weak_alias(__environ, environ);
137

148
#ifdef __EMSCRIPTEN__
9+
#include <stdlib.h>
10+
#include <wasi/api.h>
11+
// Included for emscripten_builtin_free / emscripten_builtin_malloc
12+
// TODO(sbc): Should these be in their own header to avoid emmalloc here?
13+
#include <emscripten/emmalloc.h>
14+
15+
// We use emscripten_builtin_malloc here because this memory is never freed and
16+
// and we don't want LSan to consider this a leak.
1517
__attribute__((constructor(100))) // construct this before user code
1618
void __emscripten_environ_constructor(void) {
1719
size_t environ_count;

system/lib/pthread/emscripten_tls_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* found in the LICENSE file.
66
*/
77

8+
// Included for emscripten_builtin_free / emscripten_builtin_malloc
9+
// TODO(sbc): Should these be in their own header to avoid emmalloc here?
810
#include <emscripten/emmalloc.h>
911
#include <pthread.h>
1012

system/lib/pthread/pthread_create.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <stdbool.h>
1414
#include <string.h>
1515
#include <threads.h>
16+
// Included for emscripten_builtin_free / emscripten_builtin_malloc
17+
// TODO(sbc): Should these be in their own header to avoid emmalloc here?
1618
#include <emscripten/emmalloc.h>
1719

1820
// See musl's pthread_create.c

0 commit comments

Comments
 (0)