Ugly reusing a const pointer for a non-const purpose (you're about to free() this).  I'd introduce a local non-const pointer for this, to avoid the need to cast away constness at free; otherwise, those reading the code are apt to see that cast as a red flag.