Thanks fot the code, It worked to check the pointer value returned by malloc, but after that, if repeating the function, memory never gets allocated. For some reason, when memory for _buffer is not allocated, the same happens to cleanbuffer. I thought that because this occurs sometimes, retrying...