Page 1 of 1

Missing dealloc in stmfClose()

Posted: Mon Dec 22, 2025 10:10 am
by Kyros
Hi Scott,

i was studying the code of the CSVR4 library because i was interested in Unicode stream file handling in RPGLE.

In particular i was looking at the stmfClose() procedure and i was wondering if maybe there is a missing dealloc at the end of this procedure.

This is the code i am referring to:

Code: Select all

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * stmfClose():  Close a buffered stream file
      *
      *   fp = (input) pointer to file as returned by stmfOpen
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P stmfClose       B
     D                 PI
     D  fp                             *   value

     D stmf            ds                  likeds(stmf_t)
     D                                     based(fp)
      /free

       if stmf.fd <> -1 and close(stmf.fd) <> 0;
          ReportError();
       endif;

       dealloc stmf.buf;
       stmf.fd       = -1;
       stmf.buf      = *null;
       stmf.bufPos   = *null;
       stmf.bufAlloc = 0;

      /end-free
     P                 E


Before exiting this procedure i think there should be a deallocation of the fp pointer, otherwise i think that the memory allocated by stmfOpen is never freed.

I am not 100% sure about this because i am just starting to work with dynamic memory allocation in rpgle, so excuse me if i am wrong.

Thank you for your very useful work.

Regards,

Fabio