Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-15-SP2:Update
libcdio.24379
libcdio-0.94-leak-19.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File libcdio-0.94-leak-19.patch of Package libcdio.24379
Partial patch. Backport. From 8980bdebcb68916d2b2aea91b9d76e83a1a3c574 Mon Sep 17 00:00:00 2001 From: "R. Bernstein" <rocky@gnu.org> Date: Fri, 29 Dec 2017 20:59:45 -0500 Subject: [PATCH 19/20] Memory leaks and lint found from clang "scan_build" --- configure.ac | 2 +- example/mmc3.c | 28 ++++++++++++---------- example/sample4.c | 49 +++++++++++++++++++++------------------ lib/driver/gnu_linux.c | 1 - lib/driver/image/bincue.c | 2 +- lib/driver/image/cdrdao.c | 2 +- lib/driver/image/nrg.c | 22 +++++++++++------- lib/iso9660/iso9660.c | 3 ++- lib/iso9660/iso9660_fs.c | 12 ++++++++-- lib/iso9660/rock.c | 5 ++-- src/cdda-player.c | 3 +-- test/driver/cdda.c | 11 +++++---- test/driver/mmc_read.c | 10 ++++---- test/testgetdevices.c | 46 ++++++++++++++++++------------------ test/testiso9660.c | 6 ++--- test/testisocd.c | 2 -- 16 files changed, 114 insertions(+), 90 deletions(-) Index: libcdio-0.94/example/mmc3.c =================================================================== --- libcdio-0.94.orig/example/mmc3.c +++ libcdio-0.94/example/mmc3.c @@ -1,6 +1,6 @@ /* - Copyright (C) 2006, 2008, 2009, 2011 Rocky Bernstein <rocky@gnu.org> - + Copyright (C) 2006, 2008, 2009, 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 @@ -51,8 +51,8 @@ main(int argc, const char *argv[]) char *psz_drive = NULL; bool do_eject = false; bool do_close = false; - - if (argc > 1) + + if (argc > 1) psz_drive = strdup(argv[1]); if (!psz_drive) { @@ -68,7 +68,7 @@ main(int argc, const char *argv[]) printf("-- Can't open %s\n", psz_drive); exit(77); } - + ret = mmc_get_tray_status(p_cdio); switch((int) ret) { case 0: @@ -82,28 +82,30 @@ main(int argc, const char *argv[]) default: printf("-- Error status for drive %s: %s.\n", psz_drive, cdio_driver_errmsg(ret)); + free(psz_drive); return 77; } - + ret = mmc_get_media_changed(p_cdio); switch((int) ret) { case 0: - printf("-- CD-ROM drive %s media not changed since last test.\n", + printf("-- CD-ROM drive %s media not changed since last test.\n", psz_drive); break; case 1: printf("-- CD-ROM drive %s media changed since last test.\n", psz_drive); break; default: - printf("-- Error status for drive %s: %s.\n", psz_drive, + printf("-- Error status for drive %s: %s.\n", psz_drive, cdio_driver_errmsg(ret)); + free(psz_drive); return 77; } if (do_eject && argc > 2) - ret = cdio_eject_media_drive(psz_drive); + cdio_eject_media_drive(psz_drive); else - ret = cdio_close_tray(psz_drive, &driver_id); + cdio_close_tray(psz_drive, &driver_id); ret = mmc_get_tray_status(p_cdio); switch((int) ret) { @@ -116,13 +118,14 @@ main(int argc, const char *argv[]) default: printf("Error status for drive %s: %s.\n", psz_drive, cdio_driver_errmsg(ret)); + free(psz_drive); return 77; } - + ret = mmc_get_media_changed(p_cdio); switch((int) ret) { case 0: - printf("-- CD-ROM drive %s media not changed since last test.\n", + printf("-- CD-ROM drive %s media not changed since last test.\n", psz_drive); break; case 1: @@ -131,6 +134,7 @@ main(int argc, const char *argv[]) default: printf("-- Error status for drive %s: %s.\n", psz_drive, cdio_driver_errmsg(ret)); + free(psz_drive); return 77; } Index: libcdio-0.94/example/sample4.c =================================================================== --- libcdio-0.94.orig/example/sample4.c +++ libcdio-0.94/example/sample4.c @@ -1,6 +1,6 @@ /* - Copyright (C) 2003, 2004, 2008, 2009, 2012 Rocky Bernstein <rocky@gnu.org> - + Copyright (C) 2003-2004, 2008-2009, 2012, 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 @@ -15,7 +15,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* +/* A slightly improved sample3 program: we handle cdio logging and take an optional CD-location. */ @@ -27,6 +27,9 @@ #ifdef HAVE_STDIO_H #include <stdio.h> #endif +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif #ifdef HAVE_STRING_H #include <string.h> #endif @@ -38,7 +41,7 @@ #include <cdio/cd_types.h> #include <cdio/logging.h> -static void +static void log_handler (cdio_log_level_t level, const char message[]) { switch(level) { @@ -51,7 +54,7 @@ log_handler (cdio_log_level_t level, con } static void -print_analysis(cdio_iso_analysis_t cdio_iso_analysis, +print_analysis(cdio_iso_analysis_t cdio_iso_analysis, cdio_fs_anal_t fs, int first_data, unsigned int num_audio) { switch(CDIO_FSTYPE(fs)) { @@ -111,7 +114,7 @@ print_analysis(cdio_iso_analysis_t cdio_ if (fs & CDIO_FS_ANAL_HIDDEN_TRACK) printf("Hidden Track "); if (fs & CDIO_FS_ANAL_PHOTO_CD) - printf("%sPhoto CD ", + printf("%sPhoto CD ", num_audio > 0 ? " Portfolio " : ""); if (fs & CDIO_FS_ANAL_CDTV) printf("Commodore CDTV "); @@ -134,7 +137,7 @@ main(int argc, const char *argv[]) { CdIo_t *p_cdio; cdio_fs_anal_t fs=0; - + track_t num_tracks; track_t first_track_num; lsn_t start_track; /* first sector of track */ @@ -147,7 +150,7 @@ main(int argc, const char *argv[]) unsigned int i; char *cd_image_name = NULL; - if (argc > 1) + if (argc > 1) cd_image_name = strdup(argv[1]); cdio_log_set_handler (log_handler); @@ -156,6 +159,7 @@ main(int argc, const char *argv[]) if (NULL == p_cdio) { printf("-- Problem in trying to find a driver.\n\n"); + free(cd_image_name); return 77; } @@ -178,48 +182,49 @@ main(int argc, const char *argv[]) printf("-- Audio CD\n"); } else { /* we have data track(s) */ - cdio_iso_analysis_t cdio_iso_analysis; + cdio_iso_analysis_t cdio_iso_analysis; memset(&cdio_iso_analysis, 0, sizeof(cdio_iso_analysis)); - + for (i = first_data; i <= num_tracks; i++) { lsn_t lsn; track_format_t track_format = cdio_get_track_format(p_cdio, i); - + lsn = cdio_get_track_lsn(p_cdio, i); - + switch ( track_format ) { case TRACK_FORMAT_AUDIO: case TRACK_FORMAT_ERROR: break; case TRACK_FORMAT_CDI: case TRACK_FORMAT_XA: - case TRACK_FORMAT_DATA: - case TRACK_FORMAT_PSX: + case TRACK_FORMAT_DATA: + case TRACK_FORMAT_PSX: ; } - + start_track = (i == 1) ? 0 : lsn; - + /* save the start of the data area */ - if (i == first_data) + if (i == first_data) data_start = start_track; - + /* skip tracks which belong to the current walked session */ if (start_track < data_start + cdio_iso_analysis.isofs_size) continue; - + fs = cdio_guess_cd_type(p_cdio, start_track, i, &cdio_iso_analysis); - + print_analysis(cdio_iso_analysis, fs, first_data, num_audio); - + if ( !(CDIO_FSTYPE(fs) == CDIO_FS_ISO_9660 || CDIO_FSTYPE(fs) == CDIO_FS_ISO_HFS || CDIO_FSTYPE(fs) == CDIO_FS_ISO_9660_INTERACTIVE) ) /* no method for non-ISO9660 multisessions */ - break; + break; } } + free(cd_image_name); cdio_destroy(p_cdio); 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 @@ -1580,7 +1580,6 @@ close_tray_linux (const char *psz_device cdio_info ("CDROM_DRIVE_STATUS failed: %s, trying anyway", strerror(errno)); try_anyway: - i_rc = DRIVER_OP_SUCCESS; if((i_rc = ioctl(fd, CDROMCLOSETRAY)) != 0) { cdio_warn ("ioctl CDROMCLOSETRAY failed: %s\n", strerror(errno)); i_rc = DRIVER_OP_ERROR; Index: libcdio-0.94/lib/driver/image/bincue.c =================================================================== --- libcdio-0.94.orig/lib/driver/image/bincue.c +++ libcdio-0.94/lib/driver/image/bincue.c @@ -212,7 +212,7 @@ _read_bincue (void *p_user_data, void *d final_size += this_size; memcpy (p, buf, this_size); p += this_size; - this_size = cdio_stream_read(p_env->gen.data_source, buf, rem, 1); + cdio_stream_read(p_env->gen.data_source, buf, rem, 1); /* Skip over stuff at end of this sector and the beginning of the next. */ Index: libcdio-0.94/lib/driver/image/cdrdao.c =================================================================== --- libcdio-0.94.orig/lib/driver/image/cdrdao.c +++ libcdio-0.94/lib/driver/image/cdrdao.c @@ -219,7 +219,7 @@ _read_cdrdao (void *user_data, void *dat final_size += this_size; memcpy (p, buf, this_size); p += this_size; - this_size = cdio_stream_read(this_track->data_source, buf, rem, 1); + cdio_stream_read(this_track->data_source, buf, rem, 1); /* Skip over stuff at end of this sector and the beginning of the next. */ Index: libcdio-0.94/lib/driver/image/nrg.c =================================================================== --- libcdio-0.94.orig/lib/driver/image/nrg.c +++ libcdio-0.94/lib/driver/image/nrg.c @@ -247,16 +247,15 @@ parse_nrg (_img_private_t *p_env, const entries /= sizeof (_cuex_array_t); if (CUES_ID == opcode) { - lsn_t lsn = UINT32_FROM_BE (_entries[0].lsn); unsigned int idx; unsigned int i = 0; - - cdio_debug ("CUES type image detected" ); - + lsn_t lsn; /* = UINT32_FROM_BE (_entries[0].lsn); */ /* CUES LSN has 150 pregap include at beginning? -/ cdio_assert (lsn == 0?); */ + cdio_debug ("CUES type image detected" ); + p_env->is_cues = true; /* HACK alert. */ p_env->gen.i_tracks = 0; p_env->gen.i_first_track = 1; @@ -1271,12 +1270,15 @@ cdio_is_nrg(const char *psz_nrg) _img_private_t *p_env = calloc(1, sizeof (_img_private_t)); bool is_nrg = false; - if (psz_nrg == NULL) return false; + if (psz_nrg == NULL) { + is_nrg = false; + goto exit; + } if (!(p_env->gen.data_source = cdio_stdio_new (psz_nrg))) { cdio_warn ("can't open nrg image file %s for reading", psz_nrg); - free(p_env); - return false; + is_nrg = false; + goto exit; } if (parse_nrg(p_env, psz_nrg, CDIO_LOG_INFO)) { @@ -1285,11 +1287,15 @@ cdio_is_nrg(const char *psz_nrg) size_t psz_len; psz_len = strlen(psz_nrg); /* At least 4 characters needed for .nrg extension */ - if ( psz_len < 4 ) return false; + if ( psz_len < 4 ) { + is_nrg = false; + goto exit; + } is_nrg = strncasecmp( psz_nrg+(psz_len-3), "nrg", 3 ) == 0; #endif } + exit: _free_nrg(p_env); return is_nrg; } Index: libcdio-0.94/lib/iso9660/iso9660.c =================================================================== --- libcdio-0.94.orig/lib/iso9660/iso9660.c +++ libcdio-0.94/lib/iso9660/iso9660.c @@ -781,7 +781,8 @@ iso9660_dir_add_entry_su(void *dir, ? strlen(filename) : 1); /* working hack! */ memcpy(&idr->filename.str[1], filename, from_711(idr->filename.len)); - memcpy(&dir8[offset] + su_offset, su_data, su_size); + if (su_size > 0 && su_data) + memcpy(&dir8[offset] + su_offset, su_data, su_size); } void 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 @@ -1105,7 +1105,10 @@ _fs_iso_stat_traverse (iso9660_t *p_iso, } ret = iso9660_iso_seek_read (p_iso, _dirbuf, _root->lsn, _root->secsize); - if (ret!=ISO_BLOCKSIZE*_root->secsize) return NULL; + if (ret!=ISO_BLOCKSIZE*_root->secsize) { + free(_dirbuf); + return NULL; + } while (offset < (_root->secsize * ISO_BLOCKSIZE)) { @@ -1346,12 +1349,14 @@ iso9660_fs_readdir (CdIo_t *p_cdio, cons if (!_dirbuf) { cdio_warn("Couldn't calloc(1, %d)", p_stat->secsize * ISO_BLOCKSIZE); + iso9660_stat_free(p_stat); _cdio_list_free (retval, true, NULL); return NULL; } if (cdio_read_data_sectors (p_cdio, _dirbuf, p_stat->lsn, ISO_BLOCKSIZE, p_stat->secsize)) { + iso9660_stat_free(p_stat); _cdio_list_free (retval, true, NULL); return NULL; } @@ -1689,7 +1694,10 @@ iso_have_rr_traverse (iso9660_t *p_iso, } ret = iso9660_iso_seek_read (p_iso, _dirbuf, _root->lsn, _root->secsize); - if (ret!=ISO_BLOCKSIZE*_root->secsize) return false; + if (ret!=ISO_BLOCKSIZE*_root->secsize) { + free(_dirbuf); + return false; + } while (offset < (_root->secsize * ISO_BLOCKSIZE)) { Index: libcdio-0.94/lib/iso9660/rock.c =================================================================== --- libcdio-0.94.orig/lib/iso9660/rock.c +++ libcdio-0.94/lib/iso9660/rock.c @@ -432,8 +432,9 @@ parse_rock_ridge_stat_internal(iso9660_d switch(p_sl->flags &~1){ case 0: realloc_symlink(p_stat, p_sl->len); - memcpy(&(p_stat->rr.psz_symlink[p_stat->rr.i_symlink]), - p_sl->text, p_sl->len); + if (p_sl->text && p_sl->len) + memcpy(&(p_stat->rr.psz_symlink[p_stat->rr.i_symlink]), + p_sl->text, p_sl->len); p_stat->rr.i_symlink += p_sl->len; break; case 4: Index: libcdio-0.94/src/cdda-player.c =================================================================== --- libcdio-0.94.orig/src/cdda-player.c +++ libcdio-0.94/src/cdda-player.c @@ -269,7 +269,6 @@ select_wait(int sec) fd_set se; FD_ZERO(&se); - FD_SET(0,&se); tv.tv_sec = sec; tv.tv_usec = 0; return select(1,&se,NULL,NULL,&tv); @@ -288,7 +287,7 @@ action(const char *psz_action) } if (!psz_action) - psz_action = psz_action_line; + ; else if (psz_action && strlen(psz_action)) snprintf(psz_action_line, sizeof(psz_action_line), "action : %s", psz_action); Index: libcdio-0.94/test/driver/cdda.c =================================================================== --- libcdio-0.94.orig/test/driver/cdda.c +++ libcdio-0.94/test/driver/cdda.c @@ -1,6 +1,6 @@ /* -*- C -*- Copyright (C) 2012 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 @@ -15,7 +15,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* +/* Unit test for cdda-like things lib/driver/disc.c */ #ifdef HAVE_CONFIG_H @@ -40,8 +40,9 @@ int main(int argc, const char *argv[]) { - char *mcn = cdio_get_mcn(NULL); - + char *mcn; + cdio_get_mcn(NULL); + cdio_log_set_handler(log_handler); cdio_loglevel_default = (argc > 1) ? CDIO_LOG_DEBUG : CDIO_LOG_INFO; @@ -51,6 +52,6 @@ main(int argc, const char *argv[]) printf("Should have gotten NULL for MCN for cdio object\n"); return 1; } - + return 0; } Index: libcdio-0.94/test/driver/mmc_read.c =================================================================== --- libcdio-0.94.orig/test/driver/mmc_read.c +++ libcdio-0.94/test/driver/mmc_read.c @@ -303,7 +303,7 @@ wait_for_drive(CdIo_t *p_cdio, unsigned static int test_read(char *psz_drive_path, unsigned int i_flag) { - int sense_avail = 0, i_ret, i_sense_valid, i_size, alloc_len = 10; + int sense_avail = 0, i_ret = 0, i_sense_valid, i_size, alloc_len = 10; bool b_verbose = !!(i_flag & 1); int old_log_level = cdio_loglevel_default; cdio_mmc_request_sense_t sense_reply; @@ -326,7 +326,7 @@ test_read(char *psz_drive_path, unsigned scsi_tuple = cdio_get_arg(p_cdio, "scsi-tuple"); if (scsi_tuple == NULL) { fprintf(stderr, "Error: cdio_get_arg(\"scsi-tuple\") returns NULL.\n"); - i_ret = 6; goto ex; + i_ret += 6; goto ex; } else if (i_flag & 1) printf("Drive '%s' has cdio_get_arg(\"scsi-tuple\") = '%s'\n", psz_drive_path, scsi_tuple); @@ -339,11 +339,11 @@ test_read(char *psz_drive_path, unsigned fprintf(stderr, "Error: Drive not ready. Only %d sense bytes. Expected >= 18.\n", sense_avail); - i_ret = 2; goto ex; + i_ret += 2; goto ex; } /* Cause sense reply failure by requesting inappropriate mode page 3Eh */ - i_ret = mode_sense(p_cdio, &sense_avail, &sense_reply, + i_ret += mode_sense(p_cdio, &sense_avail, &sense_reply, 0x3e, 0, alloc_len, buf, &i_size, b_verbose); if (i_ret != 0 && sense_avail < 18) { @@ -452,7 +452,7 @@ main(int argc, const char *argv[]) printf("Got status %d back from get_disc_erasable(%s)\n", i_status, psz_source); } - i_status = get_disctype(p_cdio, b_verbose); + get_disctype(p_cdio, b_verbose); if ( psz_have_mmc && 0 == strncmp("true", psz_have_mmc, sizeof("true")) ) { Index: libcdio-0.94/test/testgetdevices.c =================================================================== --- libcdio-0.94.orig/test/testgetdevices.c +++ libcdio-0.94/test/testgetdevices.c @@ -171,32 +171,34 @@ main(int argc, const char *argv[]) if (ret != 0) return ret; if (0 == chdir(DATA_DIR)) { - nrg_images = cdio_get_devices(DRIVER_NRG); - - for (imgs=nrg_images; *imgs != NULL; imgs++) { - printf("-- NRG image %s\n", *imgs); - } - - if (!is_in(nrg_images, nrg_files[0])) { - cdio_free_device_list(nrg_images); - return 10; - } - - for (i=0; i<2; i++) { - if (is_in(bincue_images, cue_files[i])) { - printf("-- %s parses as a CDRWIN BIN/CUE csheet.\n", - cue_files[i]); - } else { - printf("-- %s doesn't parse as a CDRWIN BIN/CUE csheet.\n", - cue_files[i]); - ret = i+1; - } - } + int invalid_images = 0; + nrg_images = cdio_get_devices(DRIVER_NRG); + for (imgs=nrg_images; *imgs != NULL; imgs++) { + printf("-- NRG image %s\n", *imgs); + } + + if (!is_in(nrg_images, nrg_files[0])) { + cdio_free_device_list(nrg_images); + return 10; + } + + for (i=0; i<2; i++) { + if (is_in(bincue_images, cue_files[i])) { + printf("-- %s parses as a CDRWIN BIN/CUE csheet.\n", + cue_files[i]); + } else { + printf("-- %s doesn't parse as a CDRWIN BIN/CUE csheet.\n", + cue_files[i]); + invalid_images += 1; + } + } + printf("invaid images is %d\n", invalid_images); + ret = invalid_images != 2; } cdio_free_device_list(nrg_images); cdio_free_device_list(bincue_images); - return 0; + return ret; #endif } Index: libcdio-0.94/test/testiso9660.c =================================================================== --- libcdio-0.94.orig/test/testiso9660.c +++ libcdio-0.94/test/testiso9660.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2003, 2006, 2007, 2008, 2009, 2011 + Copyright (C) 2003, 2006-2009, 2011, 2017 Rocky Bernstein <rocky@gnu.org> This program is free software: you can redistribute it and/or modify @@ -173,12 +173,12 @@ main (int argc, const char *argv[]) * Test iso9660_strncpy_pad *********************************************/ - dst_p = iso9660_strncpy_pad(dst, "1_3", 5, ISO9660_DCHARS); + iso9660_strncpy_pad(dst, "1_3", 5, ISO9660_DCHARS); if ( 0 != strncmp(dst, "1_3 ", 5) ) { printf("Failed iso9660_strncpy_pad DCHARS\n"); return 31; } - dst_p = iso9660_strncpy_pad(dst, "ABC!123", 2, ISO9660_ACHARS); + iso9660_strncpy_pad(dst, "ABC!123", 2, ISO9660_ACHARS); if ( 0 != strncmp(dst, "AB", 2) ) { printf("Failed iso9660_strncpy_pad ACHARS truncation\n"); return 32; Index: libcdio-0.94/test/testisocd.c =================================================================== --- libcdio-0.94.orig/test/testisocd.c +++ libcdio-0.94/test/testisocd.c @@ -147,8 +147,6 @@ 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