Yes, this is valid. But when you create a MEM dataset this way, you remain the owner of the buffer. It is your responsibility to you to destroy it after the MEM dataset has been destroyed (the MEM dataset wouldn't know with which method to use to free the buffer).

If you want the MEM dataset to manage the buffer, then you should use GDALCreate().