Remove more memory leaks caught by valgrind.

This commit is contained in:
rocky
2004-03-20 22:46:56 +00:00
parent 0643636d06
commit fb040eada5
9 changed files with 66 additions and 30 deletions

View File

@@ -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 <hvr@gnu.org>
Copyright (C) 2002,2003 Rocky Bernstein <rocky@panix.com>
Copyright (C) 2002, 2003, 2004 Rocky Bernstein <rocky@panix.com>
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 <stdio.h>
#include <stdlib.h>
@@ -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;
}
}