memleak fix from someone
authorDavid Schleef <ds@schleef.org>
Tue, 23 Jan 2001 18:23:20 +0000 (18:23 +0000)
committerDavid Schleef <ds@schleef.org>
Tue, 23 Jan 2001 18:23:20 +0000 (18:23 +0000)
lib/comedi.c

index 338be62357af97ffd9f768f2982129641fc29720..a2fdcda6dc35bd39c88de866cd5783efa28109d2 100644 (file)
@@ -89,11 +89,34 @@ __asm__(".symver comedi_open_0,comedi_open@");
 
 void comedi_close(comedi_t *it)
 {
-       it->magic=0;
+       subdevice *s;
+       int i;
 
-       /* XXX should free all memory */
+       it->magic=0;
 
+       for(i=0;i<it->n_subdevices;i++){
+               s=it->subdevices+i;
+               if(s->type==COMEDI_SUBD_UNUSED)
+                       continue;
+
+               if(s->subd_flags&SDF_FLAGS){
+                       free(s->flags_list);
+               }
+               if(s->subd_flags&SDF_MAXDATA){
+                       free(s->maxdata_list);
+               }
+               if(s->subd_flags&SDF_RANGETYPE){
+                       free(s->range_type_list);
+                       free(s->rangeinfo_list);
+               }else{
+                       free(s->rangeinfo);
+               }
+       }
+       if(it->subdevices){
+               free(it->subdevices);
+       }
        close(it->fd);
+       free(it);
 }
 
 int comedi_cancel(comedi_t *it,unsigned int subdevice)