Bug in ImageIO.c with freeCacheBufferReset

Trent
2013-12-02
2013-12-10
  • Trent
    Trent
    2013-12-02

    There are two places in c/nitf/source/ImageIO.c where the variable freeCacheBufferReset is initialized to 1. I believe this variable should always be initialized to 0. Failure to do so causes a double-delete fault when working with multiple-band data files.

     
  • Adam Sylvester
    Adam Sylvester
    2013-12-03

    Trent,

    Thanks for pointing this out. I agree that line 4776 looks like it should be initialized to 0 rather than 1 but why do you think line 4762 should be as well? With write caching on, if you've got blocking mode S, line 4787 will allocate a buffer per band and line 4996 tells it that it should free the buffer (freeCacheBuffer will be true for each band). With write caching on, if you don't have blocking mode S, there's just a single buffer that's allocated at line 4766 that's used for each band. So in this instance, if line 4776 was updated to set freeCacheBufferReset to 0, the first band's freeFlag would be set to free the buffer and the subsequent bands wouldn't be.

    It seems like with the current behavior, you would get a double-delete for non-S modes (which I assume is what you're seeing), but if we also changed line 4762, you'd get a memory leak for S modes (since bands after the first one wouldn't be marking that they were responsible to free their buffers).

    Let me know if you agree with this logic or if I'm missing something.
    -Adam

     
  • Adam Sylvester
    Adam Sylvester
    2013-12-10

    Trent,

    I went ahead and made the one update to line 4776 outlined above. Let me know if I've missed something and this ends up being insufficient.

    -Adam