diff --git a/example/sample5.c b/example/sample5.c index 78f36230..31d73e6b 100644 --- a/example/sample5.c +++ b/example/sample5.c @@ -1,7 +1,7 @@ /* - $Id: sample5.c,v 1.4 2003/10/02 02:59:57 rocky Exp $ + $Id: sample5.c,v 1.5 2004/03/20 22:46:56 rocky Exp $ - Copyright (C) 2003 Rocky Bernstein + Copyright (C) 2003, 2004 Rocky Bernstein This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,8 +23,15 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif +#ifdef HAVE_STDIO_H #include +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H #include +#endif #include #include #include @@ -56,6 +63,8 @@ main(int argc, const char *argv[]) } cdio_free_device_list(cd_drives); + free(cd_drives); + printf("-----\n"); cd_drives = NULL; @@ -67,9 +76,9 @@ main(int argc, const char *argv[]) printf("Drive %s\n", *c); } - cdio_free_device_list(cd_drives); } - + cdio_free_device_list(cd_drives); + free(cd_drives); printf("-----\n"); printf("CD-DA drives...\n"); @@ -81,10 +90,10 @@ main(int argc, const char *argv[]) for( c = cd_drives; *c != NULL; c++ ) { printf("drive: %s\n", *c); } - - cdio_free_device_list(cd_drives); } - + cdio_free_device_list(cd_drives); + free(cd_drives); + printf("-----\n"); cd_drives = NULL; printf("VCD drives...\n"); @@ -99,6 +108,8 @@ main(int argc, const char *argv[]) } cdio_free_device_list(cd_drives); + free(cd_drives); + return 0; } diff --git a/include/cdio/cdio.h b/include/cdio/cdio.h index e622436a..f5373e63 100644 --- a/include/cdio/cdio.h +++ b/include/cdio/cdio.h @@ -1,5 +1,5 @@ /* -*- c -*- - $Id: cdio.h,v 1.36 2004/03/06 18:30:44 rocky Exp $ + $Id: cdio.h,v 1.37 2004/03/20 22:46:57 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2003, 2004 Rocky Bernstein @@ -146,6 +146,8 @@ extern "C" { To find a CD-drive of any type, use the mask CDIO_FS_MATCH_ALL. NULL is returned if we couldn't get a default device. + It is also possible to return a non NULL but after dereferencing the + the value is NULL. This also means nothing was found. */ char ** cdio_get_devices_with_cap (char* search_devices[], cdio_fs_anal_t capabilities, bool any); diff --git a/lib/Makefile.am b/lib/Makefile.am index 666351de..2235932e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -# $Id: Makefile.am,v 1.28 2004/03/20 04:12:07 rocky Exp $ +# $Id: Makefile.am,v 1.29 2004/03/20 22:46:57 rocky Exp $ # # Copyright (C) 2003, 2004 Rocky Bernstein # @@ -40,8 +40,8 @@ # 6. If any interfaces have been removed since the last public release, # then set AGE to 0. -libcdio_la_CURRENT := 0 -libcdio_la_REVISION := 2 +libcdio_la_CURRENT := 1 +libcdio_la_REVISION := 0 libcdio_la_AGE := 0 libiso9660_la_CURRENT := 1 diff --git a/lib/_cdio_generic.c b/lib/_cdio_generic.c index 17c54375..e6391e40 100644 --- a/lib/_cdio_generic.c +++ b/lib/_cdio_generic.c @@ -1,8 +1,8 @@ /* - $Id: _cdio_generic.c,v 1.12 2004/02/07 18:53:02 rocky Exp $ + $Id: _cdio_generic.c,v 1.13 2004/03/20 22:46:57 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel - Copyright (C) 2002,2003 Rocky Bernstein + Copyright (C) 2002, 2003, 2004 Rocky Bernstein This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: _cdio_generic.c,v 1.12 2004/02/07 18:53:02 rocky Exp $"; +static const char _rcsid[] = "$Id: _cdio_generic.c,v 1.13 2004/03/20 22:46:57 rocky Exp $"; #include #include @@ -135,8 +135,6 @@ cdio_generic_stdio_free (void *user_data) if (_obj->data_source) cdio_stdio_destroy (_obj->data_source); - - free (_obj); } @@ -177,17 +175,31 @@ cdio_add_device_list(char **device_list[], const char *drive, int *num_drives) { if (NULL != drive) { unsigned int j; + + /* Check if drive is already in list. */ for (j=0; j<*num_drives; j++) { if (strcmp((*device_list)[j], drive) == 0) break; } + if (j==*num_drives) { + /* Drive not in list. Add it. */ (*num_drives)++; - *device_list = realloc(*device_list, (*num_drives) * sizeof(char *)); + if (*device_list) { + *device_list = realloc(*device_list, (*num_drives) * sizeof(char *)); + } else { + /* num_drives should be 0. Add assert? */ + *device_list = malloc((*num_drives) * sizeof(char *)); + } + (*device_list)[*num_drives-1] = strdup(drive); } } else { (*num_drives)++; - *device_list = realloc(*device_list, (*num_drives) * sizeof(char *)); + if (*device_list) { + *device_list = realloc(*device_list, (*num_drives) * sizeof(char *)); + } else { + *device_list = malloc((*num_drives) * sizeof(char *)); + } (*device_list)[*num_drives-1] = NULL; } } diff --git a/lib/cdio.c b/lib/cdio.c index 67d1b605..149f90da 100644 --- a/lib/cdio.c +++ b/lib/cdio.c @@ -1,5 +1,5 @@ /* - $Id: cdio.c,v 1.41 2004/03/10 10:57:44 rocky Exp $ + $Id: cdio.c,v 1.42 2004/03/20 22:46:57 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein Copyright (C) 2001 Herbert Valerio Riedel @@ -37,7 +37,7 @@ #include #include "cdio_private.h" -static const char _rcsid[] = "$Id: cdio.c,v 1.41 2004/03/10 10:57:44 rocky Exp $"; +static const char _rcsid[] = "$Id: cdio.c,v 1.42 2004/03/20 22:46:57 rocky Exp $"; const char *track_format2str[6] = @@ -299,7 +299,9 @@ cdio_get_devices (driver_id_t driver_id) if (cdio == NULL) return NULL; if (cdio->op.get_devices) { - return cdio->op.get_devices (); + char **devices = cdio->op.get_devices (); + cdio_destroy(cdio); + return devices; } else { return NULL; } @@ -318,6 +320,8 @@ cdio_get_devices (driver_id_t driver_id) To find a CD-drive of any type, use the mask CDIO_FS_MATCH_ALL. NULL is returned if we couldn't get a default device. + It is also possible to return a non NULL but after dereferencing the + the value is NULL. This also means nothing was found. */ char ** cdio_get_devices_with_cap (char* search_devices[], @@ -362,8 +366,8 @@ cdio_get_devices_with_cap (char* search_devices[], cdio_destroy(cdio); } } - cdio_add_device_list(&drives_ret, NULL, &num_drives); } + cdio_add_device_list(&drives_ret, NULL, &num_drives); return drives_ret; } diff --git a/lib/image/bincue.c b/lib/image/bincue.c index 00e8001c..24847fb4 100644 --- a/lib/image/bincue.c +++ b/lib/image/bincue.c @@ -1,5 +1,5 @@ /* - $Id: bincue.c,v 1.7 2004/03/20 21:54:38 rocky Exp $ + $Id: bincue.c,v 1.8 2004/03/20 22:46:57 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2002, 2003, 2004 Rocky Bernstein @@ -24,7 +24,7 @@ (*.cue). */ -static const char _rcsid[] = "$Id: bincue.c,v 1.7 2004/03/20 21:54:38 rocky Exp $"; +static const char _rcsid[] = "$Id: bincue.c,v 1.8 2004/03/20 22:46:57 rocky Exp $"; #include "cdio_assert.h" #include "cdio_private.h" @@ -736,7 +736,7 @@ cdio_get_default_device_bincue(void) { char **drives = cdio_get_devices_nrg(); char *drive = (drives[0] == NULL) ? NULL : strdup(drives[0]); - cdio_free_device_list(&drives); + cdio_free_device_list(drives); return drive; } diff --git a/lib/image/nrg.c b/lib/image/nrg.c index ade69fc6..9339b160 100644 --- a/lib/image/nrg.c +++ b/lib/image/nrg.c @@ -1,5 +1,5 @@ /* - $Id: nrg.c,v 1.3 2004/03/06 18:22:07 rocky Exp $ + $Id: nrg.c,v 1.4 2004/03/20 22:46:57 rocky Exp $ Copyright (C) 2001, 2003 Herbert Valerio Riedel Copyright (C) 2003, 2004 Rocky Bernstein @@ -48,7 +48,7 @@ #include "cdio_private.h" #include "_cdio_stdio.h" -static const char _rcsid[] = "$Id: nrg.c,v 1.3 2004/03/06 18:22:07 rocky Exp $"; +static const char _rcsid[] = "$Id: nrg.c,v 1.4 2004/03/20 22:46:57 rocky Exp $"; /* structures used */ @@ -998,6 +998,7 @@ _cdio_nrg_destroy (void *obj) if (NULL != env->mapping) _cdio_list_free (env->mapping, true); cdio_generic_stdio_free(env); + free(env); } /* @@ -1215,6 +1216,7 @@ cdio_open_nrg (const char *source_name) return ret; else { cdio_generic_stdio_free (_data); + free(_data); return NULL; } diff --git a/src/cd-info.c b/src/cd-info.c index bf7e0c49..901ff4a2 100644 --- a/src/cd-info.c +++ b/src/cd-info.c @@ -1,5 +1,5 @@ /* - $Id: cd-info.c,v 1.49 2004/02/21 13:09:12 rocky Exp $ + $Id: cd-info.c,v 1.50 2004/03/20 22:46:57 rocky Exp $ Copyright (C) 2003, 2004 Rocky Bernstein Copyright (C) 1996, 1997, 1998 Gerd Knorr @@ -840,6 +840,7 @@ main(int argc, const char *argv[]) } } cdio_free_device_list(device_list); + free(device_list); } if (opts.access_mode!=NULL) { diff --git a/test/testdefault.c b/test/testdefault.c index b52acd84..2c99db14 100644 --- a/test/testdefault.c +++ b/test/testdefault.c @@ -1,7 +1,7 @@ /* - $Id: testdefault.c,v 1.3 2003/10/03 01:33:15 rocky Exp $ + $Id: testdefault.c,v 1.4 2004/03/20 22:46:57 rocky Exp $ - Copyright (C) 2003 Rocky Bernstein + Copyright (C) 2003, 2004 Rocky Bernstein This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -123,6 +123,7 @@ main(int argc, const char *argv[]) } cdio_free_device_list(imgs); + free(imgs); printf("-----\n"); @@ -141,6 +142,7 @@ main(int argc, const char *argv[]) } cdio_free_device_list(imgs); + free(imgs); printf("-----\n"); @@ -160,6 +162,7 @@ main(int argc, const char *argv[]) } cdio_free_device_list(imgs); + free(imgs); imgs = NULL; /* Print out a list of CDDA-drives. */ @@ -180,6 +183,7 @@ main(int argc, const char *argv[]) } cdio_free_device_list(imgs); + free(imgs); return 0;