Add adbe-revocationInfoArchival attribute to CMS signedAttrs

I'm working on some PHP code for certifying PDF documents to show that the document haven't been modified since being signed.
So far I have gotten it certified except from embedded timestamp and LTV (Long Term Validation).
As far as I can understand, from looking at an example certified PDF document, there need to be a adbe-revocationInfoArchival (OID 1.2.840.113583.1.1.8) signed attribute.

I have added a -ocsp file argument for openssl cms where it reads the OCSP response file.

if (ocspfile) {
    if (!strcmp(ocspfile, "-"))
        ocspbio = BIO_new_fp(stdin, BIO_NOCLOSE);
    else
        ocspbio = BIO_new_file(ocspfile, "rb");
    if (!ocspbio) {
        BIO_printf(bio_err, "Error Opening OCSP response file\n");
        goto end;
    }
    if (!d2i_OCSP_RESPONSE_bio(ocspbio, NULL)) {
        BIO_printf(bio_err, "Error reading OCSP response\n");
        goto end;
    }
}

In CMS_add1_signer I then try to add the data to the signed attributes

if (ocspbio) {
    int NID_adbe_revocation_info_archival;
    NID_adbe_revocation_info_archival = OBJ_create("1.2.840.113583.1.1.8", "adbe-revocationInfoArchival", "Adobe PDF signature certificate revocation information");
    if (!CMS_signed_add1_attr_by_NID(si, NID_adbe_revocation_info_archival, V_ASN1_SEQUENCE, ocspbio, -1)) {
        printf("%s\n", "Failed to add attribute");
        goto err;
    }
}

This results in errors such as free(): invalid pointer: 0x0000000000ff3830.

How do I add the loaded OCSP response as a signed attribute?