Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Step:15-SP6
cdio-utils.7811
libcdio-0.94-leak-13.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File libcdio-0.94-leak-13.patch of Package cdio-utils.7811
Partial patch. Backport. From 2d30e8222310adf2b897d3971fb907537d90a7eb Mon Sep 17 00:00:00 2001 From: "R. Bernstein" <rocky@gnu.org> Date: Thu, 7 Dec 2017 18:17:39 -0500 Subject: [PATCH 13/20] Reduce memory leaks and invalid pointer accesses --- example/C++/Makefile.am | 2 +- example/C++/OO/Makefile.am | 8 +++++++- example/C++/OO/iso4.cpp | 18 +++++++++--------- lib/driver/gnu_linux.c | 2 ++ lib/iso9660/iso9660_fs.c | 10 ++++++++-- test/testisocd.c | 8 ++++++-- 6 files changed, 33 insertions(+), 15 deletions(-) Index: libcdio-0.94/example/C++/OO/Makefile.am =================================================================== --- libcdio-0.94.orig/example/C++/OO/Makefile.am +++ libcdio-0.94/example/C++/OO/Makefile.am @@ -1,4 +1,4 @@ -# Copyright (C) 2005, 2006, 2008, 2009 Rocky Bernstein <rocky@gnu.org> +# Copyright (C) 2005-2006, 2008-2009, 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 @@ -68,3 +68,9 @@ tracks_LDADD = $(LIBCDIOPP_LIBS) check_PROGRAMS = $(noinst_PROGRAMS) TESTS = $(check_PROGRAMS) + +#: run valgrind on C++ programs +check-leaks: $(check_PROGRAMS) + for p in $(check_PROGRAMS); do \ + valgrind ./$$p; \ + done Index: libcdio-0.94/example/C++/OO/iso4.cpp =================================================================== --- libcdio-0.94.orig/example/C++/OO/iso4.cpp +++ libcdio-0.94/example/C++/OO/iso4.cpp @@ -1,6 +1,6 @@ /* Copyright (C) 2006, 2008, 2009 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 @@ -23,7 +23,7 @@ use in the listing. Otherwise a compiled-in default ISO 9660 image name (that comes with the libcdio distribution) will be used. - This program can be compiled with either a C or C++ compiler. In + This program can be compiled with either a C or C++ compiler. In the distributuion we perfer C++ just to make sure we haven't broken things on the C++ side. */ @@ -72,13 +72,13 @@ main(int argc, const char *argv[]) const char *psz_path="/"; ISO9660::PVD *p_pvd; - if (argc > 1) + if (argc > 1) psz_fname = argv[1]; - else + else psz_fname = ISO9660_IMAGE; if (!p_iso->open(psz_fname, DRIVER_UNKNOWN)) { - fprintf(stderr, "Sorry, couldn't open %s as a CD or CD image.\n", + fprintf(stderr, "Sorry, couldn't open %s as a CD or CD image.\n", psz_fname); return 1; } @@ -92,8 +92,9 @@ main(int argc, const char *argv[]) print_vd_info("System ", get_system_id); print_vd_info("Volume ", get_volume_id); print_vd_info("Volume Set ", get_volumeset_id); + free(psz_str); } - + if (p_iso->readdir (psz_path, stat_vector)) { /* Iterate over the list of files. */ @@ -103,16 +104,15 @@ main(int argc, const char *argv[]) char filename[4096]; ISO9660::Stat *p_s = *i; iso9660_name_translate(p_s->p_stat->filename, filename); - printf ("%s [LSN %6d] %8u %s%s\n", + printf ("%s [LSN %6d] %8u %s%s\n", 2 == p_s->p_stat->type ? "d" : "-", p_s->p_stat->lsn, p_s->p_stat->size, psz_path, filename); delete(p_s); } - + stat_vector.clear(); } delete(p_iso); return 0; } - Index: libcdio-0.94/lib/driver/gnu_linux.c =================================================================== --- libcdio-0.94.orig/lib/driver/gnu_linux.c +++ libcdio-0.94/lib/driver/gnu_linux.c @@ -804,6 +804,8 @@ dvd_discmode_linux (_img_private_t *p_en /* See if this is a DVD. */ cdio_dvd_struct_t dvd; /* DVD READ STRUCT for layer 0. */ + memset(&dvd, 0, sizeof(dvd)); + dvd.physical.type = CDIO_DVD_STRUCT_PHYSICAL; dvd.physical.layer_num = 0; if (0 == ioctl (p_env->gen.fd, DVD_READ_STRUCT, &dvd)) { Index: libcdio-0.94/lib/iso9660/iso9660_fs.c =================================================================== --- libcdio-0.94.orig/lib/iso9660/iso9660_fs.c +++ libcdio-0.94/lib/iso9660/iso9660_fs.c @@ -1511,6 +1511,8 @@ find_lsn_recurse (void *p_image, iso9660 { _cdio_list_free (dirlist, true, free); cdio_warn("Couldn't calloc(1, %d)", len2); + free(*ppsz_full_filename); + *ppsz_full_filename = NULL; return NULL; } memcpy(ret_stat, statbuf, len2); @@ -1559,8 +1561,12 @@ iso9660_stat_t * iso9660_fs_find_lsn(CdIo_t *p_cdio, lsn_t i_lsn) { char *psz_full_filename = NULL; - return find_lsn_recurse (p_cdio, (iso9660_readdir_t *) iso9660_fs_readdir, - "/", i_lsn, &psz_full_filename); + iso9660_stat_t * p_statbuf; + p_statbuf = find_lsn_recurse (p_cdio, (iso9660_readdir_t *) iso9660_fs_readdir, + "/", i_lsn, &psz_full_filename); + if (psz_full_filename != NULL) + free(psz_full_filename); + return p_statbuf; } /*! Index: libcdio-0.94/test/testisocd.c =================================================================== --- libcdio-0.94.orig/test/testisocd.c +++ libcdio-0.94/test/testisocd.c @@ -18,6 +18,7 @@ /* Tests reading ISO 9660 info from a CD. */ #include "portable.h" +#include "cdio_assert.h" #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> @@ -103,6 +104,7 @@ main(int argc, const char *argv[]) iso9660_stat_t *p_statbuf3 = iso9660_fs_find_lsn_with_path (p_cdio, i_lsn, &psz_path); int rc=0; + const unsigned int statbuf_test_size = 100; /* Compare the two statbufs. */ if (p_statbuf->lsn != p_statbuf2->lsn || @@ -114,7 +116,8 @@ main(int argc, const char *argv[]) goto exit; } - if (0 != memcmp(p_statbuf3, p_statbuf2, sizeof(iso9660_stat_t))) { + cdio_assert(statbuf_test_size < sizeof(iso9660_stat_t)); + if (0 != memcmp(p_statbuf3, p_statbuf2, statbuf_test_size)) { fprintf(stderr, "File stat information between fs_find_lsn and " "fs_find_lsn_with_path isn't the same\n"); rc=4; @@ -131,7 +134,6 @@ main(int argc, const char *argv[]) } } else { fprintf(stderr, "Path returned for fs_find_lsn_with_path is NULL\n"); - free(psz_path); rc=6; goto exit; } @@ -145,6 +147,8 @@ main(int argc, const char *argv[]) rc=7; } exit: + if (psz_path != NULL) + free(psz_path); iso9660_stat_free(p_statbuf); iso9660_stat_free(p_statbuf2); iso9660_stat_free(p_statbuf3);
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