diff --git a/LOG b/LOG index b3b1dfaa5b..559e4e65a0 100644 --- a/LOG +++ b/LOG @@ -253,3 +253,6 @@ concurrently. Updated $yield and $thread-check in mats/thread.ms to be more tolerant of timing variability. c/types.h, mats/thread.ms, release_notes.stex +- fixed three instances of unchecked mallocs reported by laqrix in + github issue #77. + io.c, schlib.c, thread.c diff --git a/c/io.c b/c/io.c index 9de2449711..475b6c4547 100644 --- a/c/io.c +++ b/c/io.c @@ -84,7 +84,7 @@ char *S_malloc_pathname(const char *inpath) { /* if no ~ or tilde dir can't be found, copy inpath */ { size_t n = strlen(inpath) + 1; - outpath = (char *)malloc(n); + if ((outpath = (char *)malloc(n)) == NULL) S_error("expand_pathname", "malloc failed"); memcpy(outpath, inpath, n); return outpath; } diff --git a/c/schlib.c b/c/schlib.c index 9cdccaab45..9d7c6f7b97 100644 --- a/c/schlib.c +++ b/c/schlib.c @@ -217,6 +217,8 @@ void S_call_help(tc, singlep) ptr tc; IBOOL singlep; { CP(tc) = AC1(tc); jb = CREATEJMPBUF(); + if (jb == NULL) + S_error_abort("unable to allocate memory for jump buffer"); FRAME(tc, -1) = CCHAIN(tc) = Scons(Scons(jb, code), CCHAIN(tc)); switch (SETJMP(jb)) { diff --git a/c/thread.c b/c/thread.c index 8206454987..0ca73c8dcf 100644 --- a/c/thread.c +++ b/c/thread.c @@ -63,6 +63,8 @@ ptr S_create_thread_object() { ptr v = S_vector_in(space_new, 0, n); tc = (ptr)malloc(size_tc); + if (tc == (ptr)0) + S_error("fork-thread", "unable to malloc thread data structure"); memcpy((void *)tc, (void *)p_tc, size_tc); for (i = 0; i < n; i += 1)