BUG: fix the crash
BUG: fix the crash

Ok, here is the result of my analysis:

* refseriesItem must be allocated on the heap since when you add it to the Common Instance Reference Module's Referenced Series, the latter takes over ownership (thus allocating it on the stack will result in a doubled delete, automatic stack deletion and destructor in Common Instance Reference module). That led to a segfault.

* When adding the frames, you create the derivation image FG once, but you add it twice to the per frame functional groups. The same group twice is/should not be a problem when calling addFrame(), however, before going to frame 2 you remove the functional group only once(!) from per frame FG vector and you delete it from memory, however, the dangling pointer of the second addition still stays in the vector. If you then all addFrame() for the second frame, the pointer will be de-referenced inside and you get a segfault.

See the patch file for possible fix (I also moved FGDerivationImage declaration to the rest of the per frame declarations).

Two "issues" remain:

* The Derivation Image Functional Group has to be added for all frames as a per frame functional group, once you add it for a single frame. If for some frames the functional group is empty, that's fine. Actually I wondered that this has gone through dcmfg on write(), I should add/fix a corresponding check.
* For completeness, you should delete the memory of the vector containing the functional groups.

QIICR/dcmqi,QIICR/dcmqi,QIICR/dcmqi,QIICR/dcmqi,QIICR/dcmqi