Read a hyperslab of a variable-length string array


What is the right way to read a subarray of a variable-length array of type string?

I modified the example program h5ex_t_vlstring.c by creating a hyperslab. Changes are shown below. However, it ran into a Segmentation fault, failed when calling H5Dvlen_reclaim().

<     rdata = (char **) malloc (dims[0] * sizeof (char *));
>     /* create a hyperslab */
>     hsize_t count = 1;
>     hsize_t start = dims[0]/2;
>     hsize_t block = dims[0] - start;
>     H5Sselect_hyperslab(space, H5S_SELECT_SET, &start, NULL, &count, &block);
>     hid_t memspace = H5Screate_simple(1, &block, NULL);
>     rdata = (char **) malloc (block * sizeof (char *));
<     status = H5Dread (dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
>     status = H5Dread (dset, memtype, memspace, space, H5P_DEFAULT, rdata);

Core dump call stack is:

(gdb) where
#0  0x00007ff2a2475001 in free () from /lib64/
#1  0x00007ff2a3470983 in H5T__vlen_reclaim (elem=0x114ae28, dt=0x1093840, 
    alloc_info=0x7ffd43ba57e0) at ../../hdf5-1.14.0/src/H5Tvlen.c:1085
#2  0x00007ff2a33d9b94 in H5T_reclaim_cb (elem=<optimized out>, dt=<optimized out>, 
    ndim=<optimized out>, point=<optimized out>, op_data=<optimized out>)
    at ../../hdf5-1.14.0/src/H5Tconv.c:9543
#3  0x00007ff2a3396170 in H5S_select_iterate (buf=buf@entry=0x114ae10, type=type@entry=0x1093840, 
    space=space@entry=0x10ba2d0, op=op@entry=0x7ffd43ba5800, op_data=op_data@entry=0x7ffd43ba57e0)
    at ../../hdf5-1.14.0/src/H5Sselect.c:1604
#4  0x00007ff2a345b31e in H5T_reclaim (type_id=type_id@entry=216172782113784131, 
    space=space@entry=0x10ba2d0, buf=buf@entry=0x114ae10) at ../../hdf5-1.14.0/src/H5Tconv.c:9507
#5  0x00007ff2a31395ed in H5Dvlen_reclaim (type_id=216172782113784131, space_id=<optimized out>, 
    dxpl_id=792633534417207304, buf=0x114ae10) at ../../hdf5-1.14.0/src/H5Ddeprec.c:347
#6  0x000000000040102c in main () at h5ex_t_vlstring.c:127


Are you calling

status = H5Dvlen_reclaim (memtype, memspace, H5P_DEFAULT, rdata);




No, I use “space” and tried the followings, but they both gave the same seg failt.

    status = H5Dvlen_reclaim (memtype, space, H5P_DEFAULT, rdata);


    status = H5Treclaim (memtype, space, H4P_DEFAULT, rdata);


That’s what I’m saying. You SHOULD be using memspace. Otherwise you are trying to free stuff past the end of rdata.



I see. That works. Thanks.