hi all,

in the course of trying to find the filehandle-leak bug in Gem i found a weird problem with open_via_path().

can anybody find anything wrong with the attached code?
if not, try the attached patch as well.

everything works fine on linux, but on w32 i cannot close the file-handle anymore (i get an errno of EBADF, which means that fd isn't a valid open file descriptor).
which in turn results in a filehandle leak.

i notice that hardly anyone (esp. Pd itself) uses open_via_path().
is there a reason for that? is it buggy? (couldn't find anything wrong though)

i use it quite a lot, e.g. in [msgfile]; i guess nobody ever tried to open > 1000 files with msgfile on w32, so the error never appeared...


fgamsdr
IOhannes
#N canvas 355 251 450 300 10;
#X obj 165 160 findfile;
#X obj 165 113 until;
#X msg 165 132 symbol findfile-test.pd;
#X msg 165 90 100;
#X connect 1 0 2 0;
#X connect 2 0 0 0;
#X connect 3 0 1 0;
#include "m_pd.h"

#ifdef __WIN32__
# include <io.h>
#else
# include <unistd.h>
#endif

#include <stdio.h>
#include <fcntl.h>
#include <string.h>



/* ****************************************************************************** */
/* findfile : find a file */
typedef struct _findfile
{
  t_object x_obj;              /* everything */
} t_findfile;

static t_class *findfile_class;

static void findfile_read(t_findfile *x, t_symbol *filename)
{
    char buf[MAXPDSTRING], *bufptr;
    int fd=-1;
    if ((fd = open_via_path(".",
                              filename->s_name, "", 
                              buf, 
                              &bufptr, 
                              MAXPDSTRING, 
                              1)
                              ) > 0) {
                                  outlet_float(x->x_obj.ob_outlet, (t_float)1.);
                                  close(fd);
                              } else {
                                  outlet_float(x->x_obj.ob_outlet, (t_float)0.);
                              }
}


static void *findfile_new(t_symbol *s, int argc, t_atom *argv)
{
  t_findfile *x = (t_findfile *)pd_new(findfile_class);
  outlet_new(&x->x_obj, gensym("float"));
  return (x);
}

void findfile_setup(void)
{
  findfile_class = class_new(gensym("findfile"), (t_newmethod)findfile_new,
                            0, sizeof(t_findfile), 0, A_GIMME, 0);
  class_addsymbol(findfile_class, (t_method)findfile_read);
}

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
Pd-dev mailing list
[email protected]
http://lists.puredata.info/listinfo/pd-dev

Reply via email to