C++ gives you control of memory management (unlike garbage-collected languages like C# or Java which look after it for you). So, you can allocate memory with new (new[] for arrays) and de-allocate with delete (delete[] for arrays) as and when you see fit.
This can be more of a curse than a blessing - there are many ways it can go wrong. If you call 'delete' twice for the same address, you get undefined behaviour (e.g. program crash). If you allocate memory with new but fail to delete it, then you have a 'memory leak' - as your program runs it will grow and grow in memory usage.
To avoid these problems, you really need a strategy for managing memory. For every piece of memory that is allocated, it should be clear from your strategy which code 'owns' the memory and is responsible for deleting it. Two common strategies are smart pointers and RAII.
Your original code doesn't seem to have a strategy for ownership which means it could be dangerous. The code calling your function needs to assume ownership of the returned pointer and must be careful to delete it - possibly in lots of different places if your function is used widely. This explains why someone comments "just dont return allocated stuff", and why Germán suggests using a smart pointer.