From 0ee0a5832cf47993d9e09d71ce46c76f6363340e Mon Sep 17 00:00:00 2001
From: Martin Kittel <linux@martin-kittel.de>
Date: Wed, 1 Jun 2011 21:22:49 +0200
Subject: [PATCH] Fix for double free in libdvdnav, taken from dvdnav svn 1220
This patch improves slightly on the upstream version and fixes a tiny
memory leak that would leave the already processed ptl_mait info unfreed
in some cases.
---
mythtv/libs/libmythdvdnav/dvdread/ifo_read.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/mythtv/libs/libmythdvdnav/dvdread/ifo_read.c b/mythtv/libs/libmythdvdnav/dvdread/ifo_read.c
index b94ac35..dc1afdf 100644
a
|
b
|
int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) { |
1325 | 1325 | ifofile->ptl_mait = 0; |
1326 | 1326 | return 0; |
1327 | 1327 | } |
| 1328 | for(i = 0; i < ptl_mait->nr_of_countries; i++) { |
| 1329 | ptl_mait->countries[i].pf_ptl_mai = NULL; |
| 1330 | } |
1328 | 1331 | |
1329 | 1332 | for(i = 0; i < ptl_mait->nr_of_countries; i++) { |
1330 | 1333 | if(!(DVDReadBytes(ifofile->file, &ptl_mait->countries[i], PTL_MAIT_COUNTRY_SIZE))) { |
… |
… |
int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) { |
1355 | 1358 | ifofile->vmgi_mat->ptl_mait * DVD_BLOCK_LEN |
1356 | 1359 | + ptl_mait->countries[i].pf_ptl_mai_start_byte)) { |
1357 | 1360 | fprintf(stderr, "libdvdread: Unable to seek PTL_MAIT table.\n"); |
1358 | | free(ptl_mait->countries); |
1359 | | free(ptl_mait); |
| 1361 | free_ptl_mait(ptl_mait, i); |
| 1362 | ifofile->ptl_mait = NULL; |
1360 | 1363 | return 0; |
1361 | 1364 | } |
1362 | 1365 | info_length = (ptl_mait->nr_of_vtss + 1) * sizeof(pf_level_t); |
1363 | 1366 | pf_temp = (uint16_t *)malloc(info_length); |
1364 | 1367 | if(!pf_temp) { |
1365 | 1368 | free_ptl_mait(ptl_mait, i); |
| 1369 | ifofile->ptl_mait = NULL; |
1366 | 1370 | return 0; |
1367 | 1371 | } |
1368 | 1372 | if(!(DVDReadBytes(ifofile->file, pf_temp, info_length))) { |
1369 | 1373 | fprintf(stderr, "libdvdread: Unable to read PTL_MAIT table.\n"); |
1370 | 1374 | free(pf_temp); |
1371 | 1375 | free_ptl_mait(ptl_mait, i); |
| 1376 | ifofile->ptl_mait = NULL; |
1372 | 1377 | return 0; |
1373 | 1378 | } |
1374 | 1379 | for (j = 0; j < ((ptl_mait->nr_of_vtss + 1) * 8); j++) { |
… |
… |
int ifoRead_PTL_MAIT(ifo_handle_t *ifofile) { |
1378 | 1383 | if(!ptl_mait->countries[i].pf_ptl_mai) { |
1379 | 1384 | free(pf_temp); |
1380 | 1385 | free_ptl_mait(ptl_mait, i); |
| 1386 | ifofile->ptl_mait = NULL; |
1381 | 1387 | return 0; |
1382 | 1388 | } |
1383 | 1389 | { /* Transpose the array so we can use C indexing. */ |