Skip to content

Commit

Permalink
Check if malloc / calloc returned NULL (#918)
Browse files Browse the repository at this point in the history
- Also display which Jenkins node is running tests for a PR
  • Loading branch information
AnHeuermann authored Jan 28, 2021
1 parent 94de8fc commit 126bb78
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def numPhysicalCPU() {
}

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

sh ("""#!/bin/bash -x
ulimit -t 1500
${env.ASAN ? "" : "ulimit -v 6291456" /* Max 6GB per process */}
cd testsuite/partest
./runtests.pl ${env.ASAN ? "-asan": ""} -j${numPhysicalCPU()} -nocolour ${env.BRANCH_NAME == "master" ? "-notlm" : ""} -with-xml ${params.RUNTESTS_FLAG} ${extraArgs}
./runtests.pl ${env.ASAN ? "-asan": ""} ${env.ASAN ? "-j1": "-j${numPhysicalCPU()}"} -nocolour ${env.BRANCH_NAME == "master" ? "-notlm" : ""} -with-xml ${params.RUNTESTS_FLAG} ${extraArgs}
CODE=\$?
test \$CODE = 0 -o \$CODE = 7 || exit 1
"""
Expand Down Expand Up @@ -752,7 +751,7 @@ void buildOMS() {
%OMDEV%\\tools\\msys\\usr\\bin\\sh --login -c "cd `cygpath '${WORKSPACE}'` && chmod +x buildOMSimulatorWindows.sh && ./buildOMSimulatorWindows.sh && rm -f ./buildOMSimulatorWindows.sh"
""")
} else {
echo "${env.NODE_NAME}"
echo "running on node: ${env.NODE_NAME}"
def nproc = numPhysicalCPU()
sh """
${env.SHELLSTART ?: ""}
Expand Down
2 changes: 2 additions & 0 deletions src/OMSimulatorLib/MatVer4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ oms::MatVer4Matrix* oms::readMatVer4Matrix(FILE* file)
MatVer4Type_t type = (MatVer4Type_t) (matrix->header.type % 100);
size_t size = sizeofMatVer4Type(type);
matrix->data = malloc(matrix->header.mrows * matrix->header.ncols * size);
if (!matrix->data)
return NULL;
fread(matrix->data, size, matrix->header.mrows*matrix->header.ncols, file);

return matrix;
Expand Down
10 changes: 10 additions & 0 deletions src/OMSimulatorLib/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ oms_status_enu_t oms::Model::list(const oms::ComRef& cref, char** contents)

doc.save(writer);
*contents = (char*) malloc(strlen(writer.result.c_str()) + 1);
if (!*contents)
{
logError("Out of memory");
return oms_status_fatal;
}
strcpy(*contents, writer.result.c_str());
return oms_status_ok;
}
Expand Down Expand Up @@ -396,6 +401,11 @@ oms_status_enu_t oms::Model::exportSnapshot(const oms::ComRef& cref, char** cont

doc.save(writer);
*contents = (char*) malloc(strlen(writer.result.c_str()) + 1);
if (!*contents)
{
logError("Out of memory");
return oms_status_fatal;
}
strcpy(*contents, writer.result.c_str());

return oms_status_ok;
Expand Down
5 changes: 5 additions & 0 deletions src/OMSimulatorLib/OMSFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ filesystem::path oms_temp_directory_path(void)
{
#if (_WIN32)
char* val = (char*)malloc(sizeof(char)*(MAX_PATH + 1));
if (!val)
{
logError("Out of memory");
return NULL;
}
GetTempPath(MAX_PATH, val);

filesystem::path p((val!=0) ? val : "/tmp");
Expand Down
5 changes: 5 additions & 0 deletions src/OMSimulatorLib/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ oms_status_enu_t oms::System::listUnconnectedConnectors(char** contents) const
if (!msg.empty())
{
*contents = (char*) malloc(msg.length() + 1);
if (!*contents)
{
logError("Out of memory");
return oms_status_fatal;
}
strcpy(*contents, msg.c_str());
}
return oms_status_ok;
Expand Down

0 comments on commit 126bb78

Please sign in to comment.