Re: [dev] Memory access violations and leaks

From: abel deuring (a.deuring@satzbau-gmbh.de)
Date: Mon May 07 2001 - 12:06:56 PDT

  • Next message: Oliver Rauch: "Re: EOF detection"

    Henning Meier-Geinitz wrote:

    > There seem to be a memory leak in sanei/sanei_scsi.c line 1271 but I
    > haven't looked into the details.
    >

    I don't think that this is a memory leak:

      if (fd >= num_alloced)
        {
          size_t new_size, old_size;
     
          old_size = num_alloced * sizeof (fd_info[0]);
          num_alloced = fd + 8;
          new_size = num_alloced * sizeof (fd_info[0]);
          if (fd_info)
            fd_info = realloc (fd_info, new_size);
          else
            fd_info = malloc (new_size);
          memset ((char *) fd_info + old_size, 0, new_size - old_size);
          if (!fd_info)
            {
              if (!fake_fd)
                close (fd);
              return SANE_STATUS_NO_MEM;
            }
       
    }

    num_alloced is a static variable, initialized to zero, fd_info is a
    static variable too, hence malloc is only called during the first call
    of sanei_scsi_open[_extended]. A corresponding call to free is indeed
    missing, but since the memory block pointed to by fd_info should be
    available during the entire program run time, we would need to put this
    into an exit handler function.

    But fd_info is not properly initialized. I'm quite surprised that this
    did not cause problems...

    Abel

    --
    Source code, list archive, and docs: http://www.mostang.com/sane/
    To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com
    



    This archive was generated by hypermail 2b29 : Mon May 07 2001 - 10:48:31 PDT