Forget about malloc for this purpose, and especially forget about returning its result as a raw pointer. Most of the C++ Core Guidelines are nuanced and suggestions, however, I.11: Never transfer ownership by a raw pointer (T*) or reference (T&) is firm: never use a raw pointer to transfer ownership. There are better alternatives (containers, smart pointers, or in the worst case things like gsl::owner), use them. This has two advantages: 1. your code is safer and won't leak, and 2. if you stick to this convention it's clear to users of your code (and future maintainers) that they should never call free() on any pointer returned from a function, again making the code easier to reason about.
If some functions in your code base return pointers that should be free()'d and other functions return pointers that shouldn't be free()'d, you rely on the users to read the documentation and do the right thing. This makes your code harder to use, and they will inevitably get it wrong.