83671c78eef55eb7446ac4777d48ff1fdaf2d822
[ric-plt/lib/rmr.git] / src / rmr / si / src / si95 / sitrash.c
1 // vim: noet sw=4 ts=4:
2 /*
3 ==================================================================================
4     Copyright (c) 2020 Nokia
5     Copyright (c) 2020 AT&T Intellectual Property.
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18 ==================================================================================
19 */
20
21 /*
22 ***************************************************************************
23 *  
24 *  Mnemonic: sitrash
25 *  Abstract: Delete all things referenced by a struct and then free the memory.
26 *    
27 *  Returns:  Nothing
28 *  Date:     08 March 2007
29 *  Author:   E. Scott Daniels                            
30 *
31 ******************************************************************************   
32 */
33
34 #include        "sisetup.h"
35 #include                "sitransport.h"
36                  
37 extern void SItrash( int type, void *bp )
38 {
39         struct tp_blk *tp = NULL;
40         struct ioq_blk *iptr;
41         struct ioq_blk *inext;
42
43                 if( bp == NULL ) {
44                         return;
45                 }
46
47         switch( type )
48         {
49                 case IOQ_BLK:
50                         iptr = (struct ioq_blk *) bp;
51                         free( iptr->data );
52                         free( iptr->addr );
53                         free( iptr );
54                         break;
55             
56                 case TP_BLK:                                            //  we assume its off the list 
57                         tp = (struct tp_blk *) bp;
58                                                 iptr = tp->squeue; 
59                                                 while( iptr != NULL ) {
60                                 inext = iptr->next;
61
62                                 free( iptr->data );          //  we could recurse, but that seems silly 
63                                 free( iptr->addr );
64                                 free( iptr );
65
66                                                                 iptr = inext;
67                         }
68
69                                                 if( tp->fd >= 0 ) {
70                                                         CLOSE( tp->fd );
71                                                 }
72      
73                         free( tp->addr );             //  release the address bufers 
74                         free( tp->paddr );        
75                         free( tp );                   //  and release the block 
76                         break;
77         }
78 }
79