STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm)
{
    int i, idx, cnt;
    STACK_OF(X509) *sk = NULL;
    X509 *x;
    X509_OBJECT *obj;
    CRYPTO_THREAD_write_lock(ctx->ctx->lock);
    idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
    if (idx < 0) {
        X509_OBJECT *xobj = X509_OBJECT_new();
        CRYPTO_THREAD_unlock(ctx->ctx->lock);
        if (xobj == NULL)
            return NULL;
        if (!X509_STORE_CTX_get_by_subject(ctx, X509_LU_X509, nm, xobj)) {
            X509_OBJECT_free(xobj);
            return NULL;
        }
        X509_OBJECT_free(xobj);
        CRYPTO_THREAD_write_lock(ctx->ctx->lock);
        idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);
        if (idx < 0) {
            CRYPTO_THREAD_unlock(ctx->ctx->lock);
            return NULL;
        }
    }
    sk = sk_X509_new_null();
    for (i = 0; i < cnt; i++, idx++) {
        obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);
        x = obj->data.x509;
        X509_up_ref(x);
        if (!sk_X509_push(sk, x)) {
            CRYPTO_THREAD_unlock(ctx->ctx->lock);
            X509_free(x);
            sk_X509_pop_free(sk, X509_free);
            return NULL;
        }
    }
    CRYPTO_THREAD_unlock(ctx->ctx->lock);
    return sk;
}
['STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm)\n{\n    int i, idx, cnt;\n    STACK_OF(X509) *sk = NULL;\n    X509 *x;\n    X509_OBJECT *obj;\n    CRYPTO_THREAD_write_lock(ctx->ctx->lock);\n    idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);\n    if (idx < 0) {\n        X509_OBJECT *xobj = X509_OBJECT_new();\n        CRYPTO_THREAD_unlock(ctx->ctx->lock);\n        if (xobj == NULL)\n            return NULL;\n        if (!X509_STORE_CTX_get_by_subject(ctx, X509_LU_X509, nm, xobj)) {\n            X509_OBJECT_free(xobj);\n            return NULL;\n        }\n        X509_OBJECT_free(xobj);\n        CRYPTO_THREAD_write_lock(ctx->ctx->lock);\n        idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt);\n        if (idx < 0) {\n            CRYPTO_THREAD_unlock(ctx->ctx->lock);\n            return NULL;\n        }\n    }\n    sk = sk_X509_new_null();\n    for (i = 0; i < cnt; i++, idx++) {\n        obj = sk_X509_OBJECT_value(ctx->ctx->objs, idx);\n        x = obj->data.x509;\n        X509_up_ref(x);\n        if (!sk_X509_push(sk, x)) {\n            CRYPTO_THREAD_unlock(ctx->ctx->lock);\n            X509_free(x);\n            sk_X509_pop_free(sk, X509_free);\n            return NULL;\n        }\n    }\n    CRYPTO_THREAD_unlock(ctx->ctx->lock);\n    return sk;\n}', 'int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)\n{\n    if (pthread_rwlock_wrlock(lock) != 0)\n        return 0;\n    return 1;\n}', 'DEFINE_STACK_OF(X509)', 'OPENSSL_STACK *OPENSSL_sk_new_null(void)\n{\n    return OPENSSL_sk_new((OPENSSL_sk_compfunc)NULL);\n}', 'void *OPENSSL_sk_value(const OPENSSL_STACK *st, int i)\n{\n    if (st == NULL || i < 0 || i >= st->num)\n        return NULL;\n    return st->data[i];\n}']