How many other malloc calls are there in the program, that you haven't shown us?
This is cause and effect. You're posting the effect, or where you think the problem is.
Except it isn't in all likelyhood a problem at all.
Put add_copy_spec() in a separate file, and a MINIMAL main() to call it - does it crash?
My guess is that it doesn't. But if it does, you have a really good example to post.
Now, back to the cause.
The grim reality of C memory management (there isn't any) is that ANY screwup you make can have any one of these outcomes
- instant death
- death in an unrelated part of the program
- absolutely nothing happens
What to do:
Run the program in the debugger (compile with -g), and linked against
electric fence
If it's an overrun, it will trap and drop you in the debugger at the line of code which stepped off memory it didn't allocate.
Run the program under valgrind - see the manual for more details.