The zmq_msg_init_data API function has a zmq_free_fn argument that is a pointer to a function to free the data. It would be good to document and officially support the feature (ALREADY IMPLEMENTED in the source code) that passing NULL for this argument is allowed and simply means that no free function is called.
I checked the source code for both version 2.2.0 and 3.2.3, and NULL free-function arguments are supported in both.
Current man page says:
If provided, the deallocation function ffn shall be called once the data buffer is no longer required by 0MQ,
with the data and hint arguments supplied to zmq_msg_init_data().
The "If provided" is the key.
But you might come up with a better solution.