There is an obvious code duplication for the cleaning part here. The common way to avoid this is to use a ``goto end:`` that would perform the error checking before returning, or to nest tests. Either ways, duplicating the #ifdef looks bad to me.