Blame test/mpi/attr/keyval_double_free_comm.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2015 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include <mpi.h>
Packit 0848f5
#include <stdlib.h>
Packit 0848f5
#include <stdio.h>
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
/* tests multiple invocations of MPI_Comm_free_keyval on the same keyval */
Packit 0848f5
Packit 0848f5
int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra);
Packit 0848f5
int delete_fn(MPI_Comm comm, int keyval, void *attr, void *extra)
Packit 0848f5
{
Packit 0848f5
    MPI_Comm_free_keyval(&keyval);
Packit 0848f5
    return MPI_SUCCESS;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
int main(int argc, char **argv)
Packit 0848f5
{
Packit 0848f5
    MPI_Comm duped;
Packit 0848f5
    int keyval = MPI_KEYVAL_INVALID;
Packit 0848f5
    int keyval_copy = MPI_KEYVAL_INVALID;
Packit 0848f5
    int errs = 0;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
    MPI_Comm_dup(MPI_COMM_SELF, &duped);
Packit 0848f5
Packit 0848f5
    MPI_Comm_create_keyval(MPI_NULL_COPY_FN, delete_fn, &keyval, NULL);
Packit 0848f5
    keyval_copy = keyval;
Packit 0848f5
Packit 0848f5
    MPI_Comm_set_attr(MPI_COMM_SELF, keyval, NULL);
Packit 0848f5
    MPI_Comm_set_attr(duped, keyval, NULL);
Packit 0848f5
Packit 0848f5
    MPI_Comm_free(&duped);      /* first MPI_Comm_free_keyval */
Packit 0848f5
    MPI_Comm_free_keyval(&keyval);   /* second MPI_Comm_free_keyval */
Packit 0848f5
    MPI_Comm_free_keyval(&keyval_copy);      /* third MPI_Comm_free_keyval */
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();     /* fourth MPI_Comm_free_keyval */
Packit 0848f5
    return 0;
Packit 0848f5
}