Don't deallocate user-supplied buffer when freeing a filehandle.
[AROS.git] / rom / dos / freedosobject.c
blobac80406b5f90eccbd0a4ae519532b37f1e7d4e28
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include <exec/memory.h>
9 #include <proto/exec.h>
10 #include <dos/exall.h>
11 #include <dos/rdargs.h>
12 #include "dos_intern.h"
14 /*****************************************************************************
16 NAME */
17 #include <proto/dos.h>
19 AROS_LH2(void, FreeDosObject,
21 /* SYNOPSIS */
22 AROS_LHA(ULONG, type, D1),
23 AROS_LHA(APTR, ptr, D2),
25 /* LOCATION */
26 struct DosLibrary *, DOSBase, 39, Dos)
28 /* FUNCTION
29 Frees an object allocated with AllocDosObject.
31 INPUTS
32 type - object type. The same parameter as given to AllocDosObject().
33 ptr - Pointer to object.
35 RESULT
37 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 if (ptr == NULL)
52 return;
54 switch(type)
56 case DOS_FILEHANDLE:
58 struct FileHandle *fh=(struct FileHandle *)ptr;
59 if (fh->fh_Flags & FHF_OWNBUF)
60 FreeMem(BADDR(fh->fh_Buf),fh->fh_Size);
61 FreeMem(fh,sizeof(struct FileHandle));
62 break;
64 case DOS_FIB:
65 FreeMem(ptr,sizeof(struct FileInfoBlock));
66 break;
68 case DOS_STDPKT:
69 freedospacket(ptr);
70 break;
72 case DOS_EXALLCONTROL:
73 if (((struct InternalExAllControl *)ptr)->fib)
74 FreeDosObject(DOS_FIB, ((struct InternalExAllControl *)ptr)->fib);
76 FreeMem(ptr, sizeof(struct InternalExAllControl));
77 break;
79 case DOS_CLI:
81 struct CommandLineInterface *cli=(struct CommandLineInterface *)ptr;
82 BPTR *cur, *next;
83 cur=(BPTR *)BADDR(cli->cli_CommandDir);
84 FreeVec(BADDR(cli->cli_SetName));
85 FreeVec(BADDR(cli->cli_CommandName));
86 FreeVec(BADDR(cli->cli_CommandFile));
87 FreeVec(BADDR(cli->cli_Prompt));
88 FreeMem(ptr,sizeof(struct CommandLineInterface));
89 while(cur!=NULL)
91 next=(BPTR *)BADDR(cur[0]);
92 UnLock(cur[1]);
93 FreeVec(cur);
94 cur=next;
96 break;
99 FreeArgs() will not free a RDArgs without a RDA_DAList,
100 see that function for more information as to why...
102 case DOS_RDARGS:
103 if(((struct RDArgs *)ptr)->RDA_DAList != NULL)
104 FreeArgs(ptr);
105 else
106 FreeVec(ptr);
108 break;
111 AROS_LIBFUNC_EXIT
112 } /* FreeDosObject */
114 void freedospacket(struct DosPacket *dp)
116 FreeVec((APTR)(((APTR)dp)-(APTR)(&((struct StandardPacket *)0)->sp_Pkt)));