Populating a structure
A case cursor == NULL does not free(out-&gt;data).
A test i &gt; 1 is strange, and buggy. If i happens to be 1, you are leaking memory legend[0] points to.
Do not cast the result of malloc
Calling calloc in char *curstr = (char *) calloc(len+1, sizeof(char)); is an overkill:


sizeof(char) is guaranteed to be 1, and
the contents of curstr is immediately overwritten by strncpy, so its zero initialization was a waste of time.

The body of the loop spells out

    legend[i] = strdup(lgnd[i]);


in a very obfuscated way.
Given no context, it is very hard to see why do you need all that dynamic allocation at all.