seg-env: Destroy base attribute if segmentation is not possible
[strongswan.git] / src / libimcv / seg / seg_env.c
index b961589..f384192 100644 (file)
@@ -171,11 +171,6 @@ METHOD(seg_env_t, add_segment, bool,
        chunk_t msg_info;
        status_t status;
 
-       /* not all attributes might have implemented the add_segment method */
-       if (!this->base_attr->add_segment)
-       {
-               return FALSE;
-       }
        this->base_attr->add_segment(this->base_attr, segment);
        status = this->base_attr->process(this->base_attr, &attr_offset);
 
@@ -224,6 +219,7 @@ seg_env_t *seg_env_create(uint32_t base_attr_id, pa_tnc_attr_t *base_attr,
        if (max_seg_size <  PA_TNC_ATTR_HEADER_SIZE ||
                max_seg_size >= PA_TNC_ATTR_HEADER_SIZE + value.len)
        {
+               base_attr->destroy(base_attr);
                return NULL;
        }
 
@@ -238,7 +234,7 @@ seg_env_t *seg_env_create(uint32_t base_attr_id, pa_tnc_attr_t *base_attr,
                        .destroy = _destroy,
                },
                .base_attr_id = base_attr_id,
-               .base_attr = base_attr->get_ref(base_attr),
+               .base_attr = base_attr,
                .max_seg_size = max_seg_size,
                .data = base_attr->get_value(base_attr),
        );