Hi,
I'm trying to use ow-capi from owfs (http://www.owfs.org). I converted owcapi.h with h2pas. I was looking for a memory leak so I used valgrind (first experience with it). There I found something other that bothered me so I tried to solve this first. I made a little test program (test00.pas) which could reproduce the problem.
The test program :
program test00;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, owcapi
  { add your units here };

begin

writeln('test00');
end.

Inclusion of owcapi in the uses clause gives this result in valgrind :

==4515== Memcheck, a memory error detector.
==4515== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==4515== Using LibVEX rev 1575, a library for dynamic binary translation.
==4515== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==4515== Using valgrind-3.1.1, a dynamic binary instrumentation framework.
==4515== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==4515== For more details, rerun with: -v
==4515==
==4515== My PID = 4515, parent PID = 4123.  Prog and args are:
==4515==    ./test00
==4515==
==4515== Invalid free() / delete / delete[]
==4515== at 0x4020EA1: free (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==4515==    by 0x41B356D: free_mem (in /lib/libc-2.4.so)
==4515==    by 0x41B3176: __libc_freeres (in /lib/libc-2.4.so)
==4515== by 0x401D246: _vgw_freeres (in /usr/lib/valgrind/x86-linux/vgpreload_core.so) ==4515== by 0x805DE25: SYSTEM_SYSTEM_EXIT (in /home/koenraad/fpc/owcapi/test00) ==4515== by 0x80565CC: SYSTEM_DO_EXIT (in /home/koenraad/fpc/owcapi/test00)
==4515==    by 0x80481FC: main (in /home/koenraad/fpc/owcapi/test00)
==4515==  Address 0x401C668 is not stack'd, malloc'd or (recently) free'd
==4515==
==4515== Invalid free() / delete / delete[]
==4515== at 0x4020EA1: free (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==4515==    by 0x41B319E: __libc_freeres (in /lib/libc-2.4.so)
==4515== by 0x401D246: _vgw_freeres (in /usr/lib/valgrind/x86-linux/vgpreload_core.so) ==4515== by 0x805DE25: SYSTEM_SYSTEM_EXIT (in /home/koenraad/fpc/owcapi/test00) ==4515== by 0x80565CC: SYSTEM_DO_EXIT (in /home/koenraad/fpc/owcapi/test00)
==4515==    by 0x80481FC: main (in /home/koenraad/fpc/owcapi/test00)
==4515==  Address 0xFFFFFFFF is not stack'd, malloc'd or (recently) free'd
==4515==
==4515== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 7 from 1)
==4515== malloc/free: in use at exit: 0 bytes in 0 blocks.
==4515== malloc/free: 0 allocs, 2 frees, 0 bytes allocated.
==4515== For counts of detected errors, rerun with: -v
==4515== All heap blocks were freed -- no leaks are possible.
Should I worry about this ? Any hints about what could be wrong ? The program seems to run fine. I hope the atachments are accepted by the list. They are cleaned up a bit : remarks removed.
Thanks for any help you can provide.
Regards,
Koenraad Lelong.
#ifndef OWCAPI_H
#define OWCAPI_H
#include <owfs_config.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
ssize_t OW_init(        const char * params ) ;
ssize_t OW_init_args(   int argc, char ** args ) ;
ssize_t OW_get( const char * path, char ** buffer, size_t * buffer_length ) ;
ssize_t OW_put( const char * path, const char * buffer, size_t buffer_length ) ;
ssize_t OW_lread( const char * path, char * buf, const size_t size, const off_t 
offset ) ;
ssize_t OW_lwrite( const char * path, const char * buf, const size_t size, 
const off_t offset ) ;
void OW_finish( void ) ;
#ifdef __cplusplus
}
#endif
#endif /* OWCAPI_H */
unit owcapi;
interface
{$LIBRARYPATH /opt/owfs/lib}
uses baseunix;
  Type
  Pchar  = ^char;
  Psize_t  = ^size_t;
{$IFDEF FPC}
{$PACKRECORDS C}
{$ENDIF}
  function OW_init(params:Pchar):ssize_t;cdecl;external 'owcapi';
  function OW_init_args(argc:longint; args:PPchar):ssize_t;cdecl;external 
'owcapi';
  function OW_get(path:Pchar; buffer:PPchar; 
buffer_length:Psize_t):ssize_t;cdecl;external 'owcapi';
  function OW_put(path:Pchar; buffer:Pchar; 
buffer_length:size_t):ssize_t;cdecl;external 'owcapi';
  function OW_lread(path:Pchar; buf:Pchar; size:size_t; 
offset:off_t):ssize_t;cdecl;external 'owcapi';
  function OW_lwrite(path:Pchar; buf:Pchar; size:size_t; 
offset:off_t):ssize_t;cdecl;external 'owcapi';
implementation
end.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to