Skip to content

Commit 126bb78

Browse files
authored
Check if malloc / calloc returned NULL (#918)
- Also display which Jenkins node is running tests for a PR
1 parent 94de8fc commit 126bb78

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

Jenkinsfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ def numPhysicalCPU() {
699699
}
700700

701701
void partest(cache=true, extraArgs='') {
702-
echo "cache: ${cache}, asan: ${env.ASAN}"
702+
echo "cache: ${cache}, asan: ${env.ASAN}, running on node: ${env.NODE_NAME}"
703703
sh """
704704
make -C testsuite difftool resources
705705
cp -f "${env.RUNTESTDB}/"* testsuite/ || true
@@ -710,10 +710,9 @@ void partest(cache=true, extraArgs='') {
710710

711711
sh ("""#!/bin/bash -x
712712
ulimit -t 1500
713-
${env.ASAN ? "" : "ulimit -v 6291456" /* Max 6GB per process */}
714713
715714
cd testsuite/partest
716-
./runtests.pl ${env.ASAN ? "-asan": ""} -j${numPhysicalCPU()} -nocolour ${env.BRANCH_NAME == "master" ? "-notlm" : ""} -with-xml ${params.RUNTESTS_FLAG} ${extraArgs}
715+
./runtests.pl ${env.ASAN ? "-asan": ""} ${env.ASAN ? "-j1": "-j${numPhysicalCPU()}"} -nocolour ${env.BRANCH_NAME == "master" ? "-notlm" : ""} -with-xml ${params.RUNTESTS_FLAG} ${extraArgs}
717716
CODE=\$?
718717
test \$CODE = 0 -o \$CODE = 7 || exit 1
719718
"""
@@ -752,7 +751,7 @@ void buildOMS() {
752751
%OMDEV%\\tools\\msys\\usr\\bin\\sh --login -c "cd `cygpath '${WORKSPACE}'` && chmod +x buildOMSimulatorWindows.sh && ./buildOMSimulatorWindows.sh && rm -f ./buildOMSimulatorWindows.sh"
753752
""")
754753
} else {
755-
echo "${env.NODE_NAME}"
754+
echo "running on node: ${env.NODE_NAME}"
756755
def nproc = numPhysicalCPU()
757756
sh """
758757
${env.SHELLSTART ?: ""}

src/OMSimulatorLib/MatVer4.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ oms::MatVer4Matrix* oms::readMatVer4Matrix(FILE* file)
119119
MatVer4Type_t type = (MatVer4Type_t) (matrix->header.type % 100);
120120
size_t size = sizeofMatVer4Type(type);
121121
matrix->data = malloc(matrix->header.mrows * matrix->header.ncols * size);
122+
if (!matrix->data)
123+
return NULL;
122124
fread(matrix->data, size, matrix->header.mrows*matrix->header.ncols, file);
123125

124126
return matrix;

src/OMSimulatorLib/Model.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ oms_status_enu_t oms::Model::list(const oms::ComRef& cref, char** contents)
331331

332332
doc.save(writer);
333333
*contents = (char*) malloc(strlen(writer.result.c_str()) + 1);
334+
if (!*contents)
335+
{
336+
logError("Out of memory");
337+
return oms_status_fatal;
338+
}
334339
strcpy(*contents, writer.result.c_str());
335340
return oms_status_ok;
336341
}
@@ -396,6 +401,11 @@ oms_status_enu_t oms::Model::exportSnapshot(const oms::ComRef& cref, char** cont
396401

397402
doc.save(writer);
398403
*contents = (char*) malloc(strlen(writer.result.c_str()) + 1);
404+
if (!*contents)
405+
{
406+
logError("Out of memory");
407+
return oms_status_fatal;
408+
}
399409
strcpy(*contents, writer.result.c_str());
400410

401411
return oms_status_ok;

src/OMSimulatorLib/OMSFileSystem.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ filesystem::path oms_temp_directory_path(void)
5454
{
5555
#if (_WIN32)
5656
char* val = (char*)malloc(sizeof(char)*(MAX_PATH + 1));
57+
if (!val)
58+
{
59+
logError("Out of memory");
60+
return NULL;
61+
}
5762
GetTempPath(MAX_PATH, val);
5863

5964
filesystem::path p((val!=0) ? val : "/tmp");

src/OMSimulatorLib/System.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ oms_status_enu_t oms::System::listUnconnectedConnectors(char** contents) const
382382
if (!msg.empty())
383383
{
384384
*contents = (char*) malloc(msg.length() + 1);
385+
if (!*contents)
386+
{
387+
logError("Out of memory");
388+
return oms_status_fatal;
389+
}
385390
strcpy(*contents, msg.c_str());
386391
}
387392
return oms_status_ok;

0 commit comments

Comments
 (0)