All the logic in this routine feels a little overly complicated, but I'm not sure what it's doing since I haven't compiled it to see what the GUI is doing yet, so maybe it's necessary. In any case, the new attachment above creates a memory leak. If you're trying to push a uninitialized attachment to the back of the vector, you can just do:
_attachments.push_back( attachment() );