Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.2:Rings:1-MinimalX
libcdio
libcdio-0.94-leak-04.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File libcdio-0.94-leak-04.patch of Package libcdio
Partial patch. From acf1ff0fcb8cd1ec815709277fa316ca049beb66 Mon Sep 17 00:00:00 2001 From: "R. Bernstein" <rocky@gnu.org> Date: Mon, 20 Nov 2017 17:56:19 -0500 Subject: [PATCH 4/20] Reduce memory leaks... remove depricated things in dh.h Note: a reworking of ds.h is needed to handle data which has alloc memory. --- include/cdio/ds.h | 22 +++++----------- lib/driver/device.c | 3 ++- lib/iso9660/iso9660_fs.c | 10 ++++--- test/testisocd.c | 57 ++++++++++++++++++++++++++++------------ 4 files changed, 56 insertions(+), 36 deletions(-) diff --git a/include/cdio/ds.h b/include/cdio/ds.h index 6662c58a..c56c33c7 100644 --- a/include/cdio/ds.h +++ b/include/cdio/ds.h @@ -18,11 +18,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/** \file ds.h +/** \file ds.h * \brief The top-level header for list-related data structures. - Note: this header will is slated to get removed and libcdio will use - glib.h routines instead. + Note: this header will is slated to get removed and libcdio will use + glib.h routines instead. */ @@ -60,11 +53,11 @@ void _cdio_list_prepend (CdioList_t *p_list, void *p_data); void _cdio_list_append (CdioList_t *p_list, void *p_data); -void _cdio_list_foreach (CdioList_t *p_list, _cdio_list_iterfunc_t func, +void _cdio_list_foreach (CdioList_t *p_list, _cdio_list_iterfunc_t func, void *p_user_data); -CdioListNode_t *_cdio_list_find (CdioList_t *p_list, - _cdio_list_iterfunc_t cmp_func, +CdioListNode_t *_cdio_list_find (CdioList_t *p_list, + _cdio_list_iterfunc_t cmp_func, void *p_user_data); #define _CDIO_LIST_FOREACH(node, list) \ @@ -88,11 +81,10 @@ void *_cdio_list_node_data (CdioListNode_t *p_node); #endif /* CDIO_DS_H_ */ -/* +/* * Local variables: * c-file-style: "gnu" * tab-width: 8 * indent-tabs-mode: nil * End: */ - diff --git a/lib/driver/device.c b/lib/driver/device.c index 8baf9811..12dc9153 100644 --- a/lib/driver/device.c +++ b/lib/driver/device.c @@ -31,6 +31,7 @@ #include <cdio/cd_types.h> #include <cdio/logging.h> #include "cdio_private.h" +#include <cdio/util.h> #include <cdio/mmc_cmds.h> #ifdef HAVE_STDLIB_H @@ -476,7 +477,7 @@ cdio_free_device_list (char * ppsz_device_list[]) free(*ppsz_device_list); *ppsz_device_list = NULL; } - free(ppsz_device_list_save); + CDIO_FREE_IF_NOT_NULL(ppsz_device_list_save); } diff --git a/lib/iso9660/iso9660_fs.c b/lib/iso9660/iso9660_fs.c index 2620bdb2..6a781cd3 100644 --- a/lib/iso9660/iso9660_fs.c +++ b/lib/iso9660/iso9660_fs.c @@ -16,6 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* iso9660 filesystem-based routines */ + +/* FIXME: _cdio_list_free for iso9660 statbuf is insufficient because it doesn't + free bits that are allocated inside the data. */ + #if defined(HAVE_CONFIG_H) && !defined(__CDIO_CONFIG_H__) #include "config.h" @@ -753,7 +757,7 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa, uint8_t dir_len= iso9660_get_dir_len(p_iso9660_dir); iso711_t i_fname; unsigned int stat_len; - iso9660_stat_t *p_stat; + iso9660_stat_t *p_stat = NULL; bool err; if (!dir_len) return NULL; @@ -1339,8 +1343,8 @@ iso9660_fs_readdir (CdIo_t *p_cdio, const char psz_path[], bool b_mode2) cdio_assert (offset == (p_stat->secsize * ISO_BLOCKSIZE)); - free (_dirbuf); - free (p_stat); + free(_dirbuf); + iso9660_stat_free(p_stat); return retval; } } diff --git a/test/testisocd.c b/test/testisocd.c index 789d33b1..27ca635b 100644 --- a/test/testisocd.c +++ b/test/testisocd.c @@ -1,7 +1,7 @@ -/* - Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011 Rocky Bernstein +/* + Copyright (C) 2003-2008, 2011, 2017 Rocky Bernstein <rocky@gnu.org> - + 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 the Free Software Foundation, either version 3 of the License, or @@ -47,14 +47,14 @@ int main(int argc, const char *argv[]) { - char **ppsz_cd_drives; /* List of all drives with an ISO9660 filesystem. */ + char **ppsz_cd_drives = NULL; /* All drives with an ISO9660 filesystem. */ driver_id_t driver_id; /* Driver ID found */ char *psz_drive; /* Name of drive */ CdIo_t *p_cdio; /* See if we can find a device with a loaded CD-DA in it. If successful drive_id will be set. */ - ppsz_cd_drives = + ppsz_cd_drives = cdio_get_devices_with_cap_ret(NULL, CDIO_FS_ANAL_ISO9660_ANY, true, &driver_id); @@ -64,15 +64,19 @@ main(int argc, const char *argv[]) psz_drive = strdup(ppsz_cd_drives[0]); /* Don't need a list of CD's with CD-DA's any more. */ cdio_free_device_list(ppsz_cd_drives); + ppsz_cd_drives = NULL; } else { printf("-- Unable find or access a CD-ROM drive with an ISO-9660 " "filesystem.\n"); + if (ppsz_cd_drives) + cdio_free_device_list(ppsz_cd_drives); exit(SKIP_TEST_RC); } p_cdio = cdio_open (psz_drive, driver_id); if (!p_cdio) { fprintf(stderr, "Sorry, couldn't open %s\n", psz_drive); + free(psz_drive); return 1; } else { /* You make get different results looking up "/" versus "/." and the @@ -81,38 +85,53 @@ main(int argc, const char *argv[]) find "." and in that Rock-Ridge information might be found which fills in more stat information that iso9660_fs_find_lsn also will find. . Ideally iso9660_fs_stat should be fixed. */ - iso9660_stat_t *p_statbuf = iso9660_fs_stat (p_cdio, "/."); + iso9660_stat_t *p_statbuf = iso9660_fs_stat (p_cdio, "/."); + free(psz_drive); if (NULL == p_statbuf) { - fprintf(stderr, + fprintf(stderr, "Could not get ISO-9660 file information for file /.\n"); cdio_destroy(p_cdio); exit(2); } else { /* Now try getting the statbuf another way */ + char buf[ISO_BLOCKSIZE]; char *psz_path = NULL; const lsn_t i_lsn = p_statbuf->lsn; - const iso9660_stat_t *p_statbuf2 = iso9660_fs_find_lsn (p_cdio, i_lsn); - const iso9660_stat_t *p_statbuf3 = + iso9660_stat_t *p_statbuf2 = iso9660_fs_find_lsn (p_cdio, i_lsn); + + /* + // FIXME: This is for memory testing. iso966_stat_free leaves + // around junk. Some if it is in a faulty cdio_list_free() routine. + iso9660_stat_free(p_statbuf); + iso9660_stat_free(p_statbuf2); + cdio_destroy(p_cdio); + return 0; + */ + + iso9660_stat_t *p_statbuf3 = iso9660_fs_find_lsn_with_path (p_cdio, i_lsn, &psz_path); /* Compare the two statbufs. */ -#if 0 - if (0 != memcmp(p_statbuf, p_statbuf2, sizeof(iso9660_stat_t))) { -#else - if (p_statbuf->lsn != p_statbuf2->lsn || + if (p_statbuf->lsn != p_statbuf2->lsn || p_statbuf->size != p_statbuf2->size || p_statbuf->type != p_statbuf2->type) { -#endif fprintf(stderr, "File stat information between fs_stat and " "fs_find_lsn isn't the same\n"); + + iso9660_stat_free(p_statbuf); + iso9660_stat_free(p_statbuf2); + cdio_destroy(p_cdio); exit(3); } if (0 != memcmp(p_statbuf3, p_statbuf2, sizeof(iso9660_stat_t))) { fprintf(stderr, "File stat information between fs_find_lsn and " "fs_find_lsn_with_path isn't the same\n"); + iso9660_stat_free(p_statbuf2); + iso9660_stat_free(p_statbuf3); + cdio_destroy(p_cdio); exit(4); } @@ -120,25 +139,29 @@ main(int argc, const char *argv[]) if (0 != strncmp("/./", psz_path, strlen("/./"))) { fprintf(stderr, "Path returned for fs_find_lsn_with_path " "is not correct should be /./, is %s\n", psz_path); - exit(5); free(psz_path); + cdio_destroy(p_cdio); + exit(5); } } else { fprintf(stderr, "Path returned for fs_find_lsn_with_path is NULL\n"); + cdio_destroy(p_cdio); exit(6); } - + /* Try reading from the directory. */ memset (buf, 0, ISO_BLOCKSIZE); if ( 0 != cdio_read_data_sectors (p_cdio, buf, i_lsn, ISO_BLOCKSIZE, 1) ) { fprintf(stderr, "Error reading ISO 9660 file at lsn %lu\n", (long unsigned int) p_statbuf->lsn); + iso9660_stat_free(p_statbuf); + cdio_destroy(p_cdio); exit(7); } exit(0); } } - + exit(0); } -- 2.17.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor