Commit c080a8a7 authored by Jean-Paul Saman's avatar Jean-Paul Saman

tables and descriptors: check malloc return value.

Check mallocs return value.
parent a39ac177
/*****************************************************************************
* descriptor.c: descriptors functions
*----------------------------------------------------------------------------
* Copyright (C) 2001-2010 VideoLAN
* Copyright (C) 2001-2011 VideoLAN
* $Id: descriptor.c,v 1.6 2002/10/07 14:15:14 sam Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -24,7 +24,6 @@
*
*****************************************************************************/
#include "config.h"
#include <stdlib.h>
......@@ -48,33 +47,31 @@
dvbpsi_descriptor_t* dvbpsi_NewDescriptor(uint8_t i_tag, uint8_t i_length,
uint8_t* p_data)
{
dvbpsi_descriptor_t* p_descriptor
dvbpsi_descriptor_t* p_descriptor
= (dvbpsi_descriptor_t*)malloc(sizeof(dvbpsi_descriptor_t));
if(p_descriptor)
{
p_descriptor->p_data = (uint8_t*)malloc(i_length * sizeof(uint8_t));
if (p_descriptor == NULL)
return NULL;
if(p_descriptor->p_data)
p_descriptor->p_data = (uint8_t*)malloc(i_length * sizeof(uint8_t));
if (p_descriptor->p_data)
{
p_descriptor->i_tag = i_tag;
p_descriptor->i_length = i_length;
if(p_data)
memcpy(p_descriptor->p_data, p_data, i_length);
p_descriptor->p_decoded = NULL;
p_descriptor->p_next = NULL;
p_descriptor->i_tag = i_tag;
p_descriptor->i_length = i_length;
if (p_data)
memcpy(p_descriptor->p_data, p_data, i_length);
p_descriptor->p_decoded = NULL;
p_descriptor->p_next = NULL;
}
else
{
free(p_descriptor);
p_descriptor = NULL;
free(p_descriptor);
p_descriptor = NULL;
}
}
return p_descriptor;
return p_descriptor;
}
/*****************************************************************************
* dvbpsi_DeleteDescriptors
*****************************************************************************
......@@ -82,18 +79,17 @@ dvbpsi_descriptor_t* dvbpsi_NewDescriptor(uint8_t i_tag, uint8_t i_length,
*****************************************************************************/
void dvbpsi_DeleteDescriptors(dvbpsi_descriptor_t* p_descriptor)
{
while(p_descriptor != NULL)
{
dvbpsi_descriptor_t* p_next = p_descriptor->p_next;
while(p_descriptor != NULL)
{
dvbpsi_descriptor_t* p_next = p_descriptor->p_next;
if(p_descriptor->p_data != NULL)
free(p_descriptor->p_data);
if (p_descriptor->p_data != NULL)
free(p_descriptor->p_data);
if(p_descriptor->p_decoded != NULL)
free(p_descriptor->p_decoded);
if (p_descriptor->p_decoded != NULL)
free(p_descriptor->p_decoded);
free(p_descriptor);
p_descriptor = p_next;
}
free(p_descriptor);
p_descriptor = p_next;
}
}
/*****************************************************************************
* dr_02.c
* Copyright (C) 2001-2010 VideoLAN
* Copyright (C) 2001-2011 VideoLAN
* $Id: dr_02.c,v 1.7 2003/07/25 20:20:40 fenrir Exp $
*
* Authors: Arnaud de Bossoreille de Ribou <bozo@via.ecp.fr>
......@@ -21,7 +21,6 @@
*
*****************************************************************************/
#include "config.h"
#include <stdio.h>
......@@ -40,7 +39,6 @@
#include "dr_02.h"
/*****************************************************************************
* dvbpsi_DecodeVStreamDr
*****************************************************************************/
......@@ -62,7 +60,6 @@ dvbpsi_vstream_dr_t * dvbpsi_DecodeVStreamDr(dvbpsi_descriptor_t * p_descriptor)
/* Decode data and check the length */
p_decoded->b_mpeg2 = (p_descriptor->p_data[0] & 0x04) ? 1 : 0;
if( (!p_decoded->b_mpeg2 && (p_descriptor->i_length != 1))
|| (p_decoded->b_mpeg2 && (p_descriptor->i_length != 3)))
{
......
......@@ -401,10 +401,14 @@ void dvbpsi_GatherBATSections(dvbpsi_t *p_dvbpsi,
{
p_bat_decoder->p_building_bat =
(dvbpsi_bat_t*)malloc(sizeof(dvbpsi_bat_t));
dvbpsi_InitBAT(p_bat_decoder->p_building_bat,
p_section->i_extension,
p_section->i_version,
p_section->b_current_next);
if (p_bat_decoder->p_building_bat)
dvbpsi_InitBAT(p_bat_decoder->p_building_bat,
p_section->i_extension,
p_section->i_version,
p_section->b_current_next);
else
dvbpsi_error(p_dvbpsi, "BAT decoder", "failed decoding BAT section");
p_bat_decoder->i_last_section_number = p_section->i_last_number;
}
......
......@@ -280,9 +280,11 @@ void dvbpsi_GatherCATSections(dvbpsi_t *p_dvbpsi,
{
p_cat_decoder->p_building_cat =
(dvbpsi_cat_t*)malloc(sizeof(dvbpsi_cat_t));
dvbpsi_InitCAT(p_cat_decoder->p_building_cat,
p_section->i_version,
p_section->b_current_next);
if (p_cat_decoder->p_building_cat)
dvbpsi_InitCAT(p_cat_decoder->p_building_cat,
p_section->i_version, p_section->b_current_next);
else
dvbpsi_error(p_dvbpsi, "CAT decoder", "failed decoding section");
p_cat_decoder->i_last_section_number = p_section->i_last_number;
}
......
......@@ -392,10 +392,13 @@ void dvbpsi_GatherNITSections(dvbpsi_t *p_dvbpsi,
if (!p_nit_decoder->p_building_nit)
{
p_nit_decoder->p_building_nit = (dvbpsi_nit_t*)malloc(sizeof(dvbpsi_nit_t));
dvbpsi_InitNIT(p_nit_decoder->p_building_nit,
p_nit_decoder->i_network_id,
p_section->i_version,
p_section->b_current_next);
if (p_nit_decoder->p_building_nit)
dvbpsi_InitNIT(p_nit_decoder->p_building_nit,
p_nit_decoder->i_network_id,
p_section->i_version,
p_section->b_current_next);
else
dvbpsi_debug(p_dvbpsi, "NIT decoder", "failed decoding section");
p_nit_decoder->i_last_section_number = p_section->i_last_number;
}
......
......@@ -304,10 +304,14 @@ void dvbpsi_GatherPATSections(dvbpsi_t* p_dvbpsi, dvbpsi_psi_section_t* p_sectio
{
p_pat_decoder->p_building_pat =
(dvbpsi_pat_t*)malloc(sizeof(dvbpsi_pat_t));
dvbpsi_InitPAT(p_pat_decoder->p_building_pat,
p_section->i_extension,
p_section->i_version,
p_section->b_current_next);
if (p_pat_decoder->p_building_pat)
dvbpsi_InitPAT(p_pat_decoder->p_building_pat,
p_section->i_extension,
p_section->i_version,
p_section->b_current_next);
else
dvbpsi_error(p_dvbpsi, "PAT decoder", "failed decoding section" );
p_pat_decoder->i_last_section_number = p_section->i_last_number;
}
......
......@@ -361,12 +361,15 @@ void dvbpsi_GatherPMTSections(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t* p_sectio
{
p_pmt_decoder->p_building_pmt =
(dvbpsi_pmt_t*)malloc(sizeof(dvbpsi_pmt_t));
dvbpsi_InitPMT(p_pmt_decoder->p_building_pmt,
p_pmt_decoder->i_program_number,
p_section->i_version,
p_section->b_current_next,
((uint16_t)(p_section->p_payload_start[0] & 0x1f) << 8)
| p_section->p_payload_start[1]);
if (p_pmt_decoder->p_building_pmt)
dvbpsi_InitPMT(p_pmt_decoder->p_building_pmt,
p_pmt_decoder->i_program_number,
p_section->i_version,
p_section->b_current_next,
((uint16_t)(p_section->p_payload_start[0] & 0x1f) << 8)
| p_section->p_payload_start[1]);
else
dvbpsi_debug(p_dvbpsi, "PMT decoder", "failed decoding section");
p_pmt_decoder->i_last_section_number = p_section->i_last_number;
}
......
......@@ -321,8 +321,10 @@ void dvbpsi_GatherSISSections(dvbpsi_t *p_dvbpsi,
{
p_sis_decoder->p_building_sis =
(dvbpsi_sis_t*)malloc(sizeof(dvbpsi_sis_t));
// FIXME: potiential crash on OUT OF MEMORY
dvbpsi_InitSIS(p_sis_decoder->p_building_sis, 0);
if (p_sis_decoder->p_building_sis)
dvbpsi_InitSIS(p_sis_decoder->p_building_sis, 0);
else
dvbpsi_error(p_dvbpsi, "SIS decoder", "failed decoding section");
}
}
else
......
......@@ -234,11 +234,14 @@ void dvbpsi_GatherTOTSections(dvbpsi_t* p_dvbpsi,
}
p_building_tot = (dvbpsi_tot_t*)malloc(sizeof(dvbpsi_tot_t));
dvbpsi_InitTOT(p_building_tot, ((uint64_t)p_section->p_payload_start[0] << 32)
if (p_building_tot)
dvbpsi_InitTOT(p_building_tot, ((uint64_t)p_section->p_payload_start[0] << 32)
| ((uint64_t)p_section->p_payload_start[1] << 24)
| ((uint64_t)p_section->p_payload_start[2] << 16)
| ((uint64_t)p_section->p_payload_start[3] << 8)
| (uint64_t)p_section->p_payload_start[4]);
else
dvbpsi_error(p_dvbpsi, "TOT decoder", "failed decoding section");
/* Decode the section */
dvbpsi_DecodeTOTSections(p_dvbpsi, p_building_tot, p_section);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment