diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 93fbb3a4bb3..f42a88f8831 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -1004,7 +1004,8 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope) const Variable* argvar = tok->function()->getArgumentVar(argnr); if (!argvar || !argvar->valueType()) continue; - if (argvar->valueType()->typeSize(mSettings->platform, /*p*/ true) >= mSettings->platform.sizeof_pointer) + const MathLib::bigint argSize = argvar->valueType()->typeSize(mSettings->platform, /*p*/ true); + if (argSize <= 0 || argSize >= mSettings->platform.sizeof_pointer) continue; } functionCallLeak(arg, arg->str(), functionName); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 131116f5198..7358cd97fb6 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -2493,6 +2493,13 @@ class TestMemleakNoVar : public TestFixture { " g(1, new int());\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("void f(T t);\n" + "struct U {};\n" + "void g() {\n" + " f(new U());\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void missingAssignment() {