freeing properly

diff --git a/skeletons/constr_SET_OF.c b/skeletons/constr_SET_OF.c
index e6ba985..11eac57 100644
--- a/skeletons/constr_SET_OF.c
+++ b/skeletons/constr_SET_OF.c
@@ -808,16 +808,16 @@
 
 		asn_set_empty(list);	/* Remove (list->array) */
 
-		if(!contents_only) {
-			FREEMEM(ptr);
-		}
-
 		specs = (asn_SET_OF_specifics_t *)td->specifics;
 		ctx = (asn_struct_ctx_t *)((char *)ptr + specs->ctx_offset);
 		if(ctx->ptr) {
 			ASN_STRUCT_FREE(*elm->type, ctx->ptr);
 			ctx->ptr = 0;
 		}
+
+		if(!contents_only) {
+			FREEMEM(ptr);
+		}
 	}
 }