libdvbv5/dvb-scan: fix memory leak
authorMauro Carvalho Chehab <m.chehab@samsung.com>
Sun, 17 Nov 2013 12:51:03 +0000 (10:51 -0200)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Wed, 27 Nov 2013 11:24:40 +0000 (09:24 -0200)
As pointed by Valgrind, there are still some memory leaks at
dvb_get_ts_tables().

That happens because pmt is allocated by dvb_read_section().
Fix it.

While here, fix the error condition to not mangle with the main
dvb_scan_handler->program pointer.

Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
lib/libdvbv5/dvb-scan.c

index e3d74a9..3d34c3e 100644 (file)
@@ -306,7 +306,6 @@ struct dvb_v5_descriptors *dvb_get_ts_tables(struct dvb_v5_fe_parms *parms,
        }
 
        /* PMT tables */
-
        dvb_scan_handler->program = calloc(dvb_scan_handler->pat->programs,
                                           sizeof(*dvb_scan_handler->program));
 
@@ -320,8 +319,6 @@ struct dvb_v5_descriptors *dvb_get_ts_tables(struct dvb_v5_fe_parms *parms,
                        continue;
                }
 
-               dvb_scan_handler->program[num_pmt].pmt = calloc(1, sizeof(*dvb_scan_handler->program[num_pmt].pmt));
-
                dvb_log("Program ID %d", program->pid);
                rc = dvb_read_section(parms, dmx_fd,
                                      DVB_TABLE_PMT, program->pid,
@@ -331,8 +328,7 @@ struct dvb_v5_descriptors *dvb_get_ts_tables(struct dvb_v5_fe_parms *parms,
                        fprintf(stderr,
                                "error while reading the PMT table for service 0x%04x\n",
                                program->service_id);
-                       free(dvb_scan_handler->program->pmt);
-                       dvb_scan_handler->program->pmt = NULL;
+                       dvb_scan_handler->program[num_pmt].pmt = NULL;
                } else {
                        if (verbose)
                                dvb_table_pmt_print(parms, dvb_scan_handler->program[num_pmt].pmt);