FreeCalypso > hg > fc-magnetite
view src/g23m-gprs/sndcp/sndcp_ciaf.c @ 516:1ed9de6c90bd
src/g23m-gsm/sms/sms_for.c: bogus malloc removed
The new error handling code that was not present in TCS211 blob version
contains a malloc call that is bogus for 3 reasons:
1) The memory allocation in question is not needed in the first place;
2) libc malloc is used instead of one of the firmware's proper ways;
3) The memory allocation is made inside a function and then never freed,
i.e., a memory leak.
This bug was caught in gcc-built FreeCalypso fw projects (Citrine
and Selenite) because our gcc environment does not allow any use of
libc malloc (any reference to malloc produces a link failure),
but this code from TCS3.2 is wrong even for Magnetite: if this code
path is executed repeatedly over a long time, the many small allocations
made by this malloc call without a subsequent free will eventually
exhaust the malloc heap provided by the TMS470 environment, malloc will
start returning NULL, and the bogus code will treat it as an error.
Because the memory allocation in question is not needed at all,
the fix entails simply removing it.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 22 Jul 2018 06:04:49 +0000 |
parents | 219afcfc6250 |
children |
line wrap: on
line source
/* +----------------------------------------------------------------------------- | Project : GPRS (8441) | Modul : tgen_gprs.cpp +----------------------------------------------------------------------------- | Copyright 2002 Texas Instruments Berlin, AG | All rights reserved. | | This file is confidential and a trade secret of Texas | Instruments Berlin, AG | The receipt of or possession of this file does not convey | any rights to reproduce or disclose its contents or to | manufacture, use, or sell anything it may describe, in | whole, or in part, without the specific written consent of | Texas Instruments Berlin, AG. +----------------------------------------------------------------------------- | Purpose : This modul is part of the entity SNDCP and implements all | procedures and functions as described in the | SDL-documentation (CIA-statemachine) +----------------------------------------------------------------------------- */ #define ENTITY_SNDCP /*==== INCLUDES =============================================================*/ #include "typedefs.h" /* to get Condat data types */ #include "vsi.h" /* to get a lot of macros */ #include "macdef.h" #include "prim.h" /* to get the definitions of used SAP and directions */ #include "dti.h" #include "sndcp.h" /* to get the global entity definitions */ #include "sndcp_f.h" /* to get the functions to access the global arrays*/ #ifdef _SNDCP_DTI_2_ #include <string.h> /* to get memcpy() */ #endif /*==== CONST ================================================================*/ /*==== LOCAL VARS ===========================================================*/ /*==== PRIVATE FUNCTIONS ====================================================*/ /*==== PUBLIC FUNCTIONS =====================================================*/ /* +------------------------------------------------------------------------------ | Function : cia_compress_init +------------------------------------------------------------------------------ | Description : This routine initializes the state structure for both the transmit | and receive halves of some serial line. It must be called each | time the line is brought up. | | Parameters : number of slots (from 0 to MAX_STATES) | +------------------------------------------------------------------------------ */ GLOBAL void cia_compress_init(UBYTE number_of_slots) { UBYTE i; struct cstate *tstate = sndcp_data->cia.comp.tstate; struct cstate *rstate = sndcp_data->cia.comp.rstate; TRACE_FUNCTION( "cia_compress_init"); memset((char *)&(sndcp_data->cia.comp), 0, sizeof(sndcp_data->cia.comp)); for (i = number_of_slots; i > 0; --i) { tstate[i].cs_id = i; tstate[i].cs_next = &tstate[i - 1]; tstate[i].cs_ip = (T_SNDCP_IP_HEADER*)tstate[i].cs_hdr; } tstate[0].cs_next = &tstate[number_of_slots]; tstate[0].cs_id = 0; tstate[0].cs_ip = (T_SNDCP_IP_HEADER*)tstate[0].cs_hdr; sndcp_data->cia.comp.last_cs = &tstate[0]; sndcp_data->cia.comp.last_recv = 255; sndcp_data->cia.comp.last_xmit = 255; sndcp_data->cia.comp.flags = SLF_TOSS; for (i = number_of_slots; i > 0; --i) { rstate[i].cs_id = i; rstate[i].cs_next = &rstate[i - 1]; rstate[i].cs_ip = (T_SNDCP_IP_HEADER*)rstate[i].cs_hdr; } rstate[0].cs_next = &rstate[number_of_slots]; rstate[0].cs_id = 0; rstate[0].cs_ip = (T_SNDCP_IP_HEADER*)rstate[0].cs_hdr; sndcp_data->cia.comp.slots_to_use = number_of_slots + 1; } /* +------------------------------------------------------------------------------ | Function : cia_init +------------------------------------------------------------------------------ | Description : | | Parameters : | +------------------------------------------------------------------------------ */ GLOBAL void cia_init (void) { UBYTE nsapi; TRACE_FUNCTION( "cia_init" ); INIT_STATE(CIA, CIA_DEFAULT); sndcp_reset_xid_block(&sndcp_data->cia.cur_xid_block); for (nsapi = 0; nsapi < SNDCP_NUMBER_OF_NSAPIS; nsapi ++){ sndcp_data->cia.cur_cia_decomp_ind[nsapi] = NULL; #ifdef SNDCP_TRACE_ALL sndcp_data->cia.cia_decomp_ind_number[nsapi] = 0; #endif } } /* cia_init() */