42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/client.h"
45 #include "magick/configure.h"
46 #include "magick/exception.h"
47 #include "magick/exception-private.h"
48 #include "magick/hashmap.h"
49 #include "magick/magic.h"
50 #include "magick/memory_.h"
51 #include "magick/semaphore.h"
52 #include "magick/string_.h"
53 #include "magick/string-private.h"
54 #include "magick/token.h"
55 #include "magick/utility.h"
56 #include "magick/xml-tree.h"
57 #include "magick/xml-tree-private.h"
62 #define MagicFilename "magic.xml"
63 #define MagicPattern(magic) (const unsigned char *) (magic), sizeof(magic)-1
73 const MagickOffsetType
89 {
"8BIMWTEXT", 0, MagicPattern(
"8\000B\000I\000M\000#") },
90 {
"8BIMTEXT", 0, MagicPattern(
"8BIM#") },
91 {
"8BIM", 0, MagicPattern(
"8BIM") },
92 {
"AVIF", 4, MagicPattern(
"ftypavif") },
93 {
"BMP", 0, MagicPattern(
"BA") },
94 {
"BMP", 0, MagicPattern(
"BM") },
95 {
"BMP", 0, MagicPattern(
"CI") },
96 {
"BMP", 0, MagicPattern(
"CP") },
97 {
"BMP", 0, MagicPattern(
"IC") },
98 {
"PICT", 0, MagicPattern(
"PICT") },
99 {
"BMP", 0, MagicPattern(
"PI") },
100 {
"CALS", 21, MagicPattern(
"version: MIL-STD-1840") },
101 {
"CALS", 0, MagicPattern(
"srcdocid:") },
102 {
"CALS", 9, MagicPattern(
"srcdocid:") },
103 {
"CALS", 8, MagicPattern(
"rorient:") },
104 {
"CGM", 0, MagicPattern(
"BEGMF") },
105 {
"CIN", 0, MagicPattern(
"\200\052\137\327") },
106 {
"CRW", 0, MagicPattern(
"II\x1a\x00\x00\x00HEAPCCDR") },
107 {
"DCM", 128, MagicPattern(
"DICM") },
108 {
"DCX", 0, MagicPattern(
"\261\150\336\72") },
109 {
"DIB", 0, MagicPattern(
"\050\000") },
110 {
"DDS", 0, MagicPattern(
"DDS ") },
111 {
"DJVU", 0, MagicPattern(
"AT&TFORM") },
112 {
"DOT", 0, MagicPattern(
"digraph") },
113 {
"DPX", 0, MagicPattern(
"SDPX") },
114 {
"DPX", 0, MagicPattern(
"XPDS") },
115 {
"EMF", 40, MagicPattern(
"\040\105\115\106\000\000\001\000") },
116 {
"EPT", 0, MagicPattern(
"\305\320\323\306") },
117 {
"EXR", 0, MagicPattern(
"\166\057\061\001") },
118 {
"FAX", 0, MagicPattern(
"DFAX") },
119 {
"FIG", 0, MagicPattern(
"#FIG") },
120 {
"FITS", 0, MagicPattern(
"IT0") },
121 {
"FITS", 0, MagicPattern(
"SIMPLE") },
122 {
"FLIF", 0, MagicPattern(
"FLIF") },
123 {
"GIF", 0, MagicPattern(
"GIF8") },
124 {
"GPLT", 0, MagicPattern(
"#!/usr/local/bin/gnuplot") },
125 {
"HDF", 1, MagicPattern(
"HDF") },
126 {
"HDR", 0, MagicPattern(
"#?RADIANCE") },
127 {
"HDR", 0, MagicPattern(
"#?RGBE") },
128 {
"HEIC", 4, MagicPattern(
"ftypheic") },
129 {
"HEIC", 4, MagicPattern(
"ftypheix") },
130 {
"HEIC", 4, MagicPattern(
"ftypmif1") },
131 {
"HPGL", 0, MagicPattern(
"IN;") },
132 {
"HTML", 1, MagicPattern(
"HTML") },
133 {
"HTML", 1, MagicPattern(
"html") },
134 {
"ILBM", 8, MagicPattern(
"ILBM") },
135 {
"IPTCWTEXT", 0, MagicPattern(
"\062\000#\000\060\000=\000\042\000&\000#\000\060\000;\000&\000#\000\062\000;\000\042\000") },
136 {
"IPTCTEXT", 0, MagicPattern(
"2#0=\042�\042") },
137 {
"IPTC", 0, MagicPattern(
"\034\002") },
138 {
"JNG", 0, MagicPattern(
"\213JNG\r\n\032\n") },
139 {
"JPEG", 0, MagicPattern(
"\377\330\377") },
140 {
"J2K", 0, MagicPattern(
"\xff\x4f\xff\x51") },
141 {
"JPC", 0, MagicPattern(
"\x0d\x0a\x87\x0a") },
142 {
"JP2", 0, MagicPattern(
"\x00\x00\x00\x0c\x6a\x50\x20\x20\x0d\x0a\x87\x0a") },
143 {
"MAT", 0, MagicPattern(
"MATLAB 5.0 MAT-file,") },
144 {
"MIFF", 0, MagicPattern(
"Id=ImageMagick") },
145 {
"MIFF", 0, MagicPattern(
"id=ImageMagick") },
146 {
"MNG", 0, MagicPattern(
"\212MNG\r\n\032\n") },
147 {
"MPC", 0, MagicPattern(
"id=MagickCache") },
148 {
"MPEG", 0, MagicPattern(
"\000\000\001\263") },
149 {
"MRW", 0, MagicPattern(
"\x00MRM") },
150 {
"ORF", 0, MagicPattern(
"IIRO\x08\x00\x00\x00") },
151 {
"PCD", 2048, MagicPattern(
"PCD_") },
152 {
"PCL", 0, MagicPattern(
"\033E\033") },
153 {
"PCX", 0, MagicPattern(
"\012\002") },
154 {
"PCX", 0, MagicPattern(
"\012\005") },
155 {
"PDB", 60, MagicPattern(
"vIMGView") },
156 {
"PDF", 0, MagicPattern(
"%PDF-") },
157 {
"PES", 0, MagicPattern(
"#PES") },
158 {
"PFA", 0, MagicPattern(
"%!PS-AdobeFont-1.0") },
159 {
"PFB", 6, MagicPattern(
"%!PS-AdobeFont-1.0") },
160 {
"PGX", 0, MagicPattern(
"PG ML") },
161 {
"PGX", 0, MagicPattern(
"PG LM") },
162 {
"PICT", 522, MagicPattern(
"\000\021\002\377\014\000") },
163 {
"PNG", 0, MagicPattern(
"\211PNG\r\n\032\n") },
164 {
"PBM", 0, MagicPattern(
"P1") },
165 {
"PGM", 0, MagicPattern(
"P2") },
166 {
"PPM", 0, MagicPattern(
"P3") },
167 {
"PBM", 0, MagicPattern(
"P4") },
168 {
"PGM", 0, MagicPattern(
"P5") },
169 {
"PPM", 0, MagicPattern(
"P6") },
170 {
"PAM", 0, MagicPattern(
"P7") },
171 {
"PFM", 0, MagicPattern(
"PF") },
172 {
"PFM", 0, MagicPattern(
"Pf") },
173 {
"PS", 0, MagicPattern(
"%!") },
174 {
"PS", 0, MagicPattern(
"\004%!") },
175 {
"PS", 0, MagicPattern(
"\305\320\323\306") },
176 {
"PSB", 0, MagicPattern(
"8BPB") },
177 {
"PSD", 0, MagicPattern(
"8BPS") },
178 {
"PWP", 0, MagicPattern(
"SFW95") },
179 {
"RAF", 0, MagicPattern(
"FUJIFILMCCD-RAW ") },
180 {
"RLE", 0, MagicPattern(
"\122\314") },
181 {
"SCT", 0, MagicPattern(
"CT") },
182 {
"SFW", 0, MagicPattern(
"SFW94") },
183 {
"SGI", 0, MagicPattern(
"\001\332") },
184 {
"SUN", 0, MagicPattern(
"\131\246\152\225") },
185 {
"SVG", 1, MagicPattern(
"?XML") },
186 {
"SVG", 1, MagicPattern(
"?xml") },
187 {
"SVG", 1, MagicPattern(
"SVG") },
188 {
"SVG", 1, MagicPattern(
"svg") },
189 {
"TIFF", 0, MagicPattern(
"\115\115\000\052") },
190 {
"TIFF", 0, MagicPattern(
"\111\111\052\000") },
191 {
"TIFF64", 0, MagicPattern(
"\115\115\000\053\000\010\000\000") },
192 {
"TIFF64", 0, MagicPattern(
"\111\111\053\000\010\000\000\000") },
193 {
"TTF", 0, MagicPattern(
"\000\001\000\000\000") },
194 {
"TXT", 0, MagicPattern(
"# ImageMagick pixel enumeration:") },
195 {
"VICAR", 0, MagicPattern(
"LBLSIZE") },
196 {
"VICAR", 0, MagicPattern(
"NJPL1I") },
197 {
"VIFF", 0, MagicPattern(
"\253\001") },
198 {
"WEBP", 8, MagicPattern(
"WEBP") },
199 {
"WMF", 0, MagicPattern(
"\327\315\306\232") },
200 {
"WMF", 0, MagicPattern(
"\001\000\011\000") },
201 {
"WPG", 0, MagicPattern(
"\377WPC") },
202 {
"XBM", 0, MagicPattern(
"#define") },
203 {
"XCF", 0, MagicPattern(
"gimp xcf") },
204 {
"XEF", 0, MagicPattern(
"FOVb") },
205 {
"XPM", 1, MagicPattern(
"* XPM *") }
217 static MagickBooleanType
220 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
221 static MagickBooleanType
222 LoadMagicCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
252 static int CompareMagickInfoSize(
const void *a,
const void *b)
260 if (ma->offset != mb->offset)
261 return((
int) (ma->offset-mb->offset));
262 return((
int) (mb->length-(ssize_t) ma->length));
277 cache=NewLinkedList(0);
279 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
284 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
296 options=GetConfigureOptions(filename,exception);
297 option=(
const StringInfo *) GetNextValueInLinkedList(options);
300 (void) CopyMagickString(path,GetStringInfoPath(option),MaxTextExtent);
301 status&=LoadMagicCache(cache,(
const char *)
302 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
303 option=(
const StringInfo *) GetNextValueInLinkedList(options);
305 options=DestroyConfigureOptions(options);
311 for (i=0; i < (ssize_t) (
sizeof(MagicMap)/
sizeof(*MagicMap)); i++)
320 magic_info=(
MagicInfo *) AcquireMagickMemory(
sizeof(*magic_info));
323 (void) ThrowMagickException(exception,GetMagickModule(),
324 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",p->name);
327 (void) memset(magic_info,0,
sizeof(*magic_info));
328 magic_info->path=(
char *)
"[built-in]";
329 magic_info->name=(
char *) p->name;
330 magic_info->offset=p->offset;
331 magic_info->target=(
char *) p->magic;
332 magic_info->magic=(
unsigned char *) p->magic;
333 magic_info->length=p->length;
334 magic_info->exempt=MagickTrue;
335 magic_info->signature=MagickCoreSignature;
336 status&=InsertValueInSortedLinkedList(cache,CompareMagickInfoSize,
338 if (status == MagickFalse)
339 (void) ThrowMagickException(exception,GetMagickModule(),
340 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",magic_info->name);
374 MagickExport
const MagicInfo *GetMagicInfo(
const unsigned char *magic,
381 if (IsMagicCacheInstantiated(exception) == MagickFalse)
386 LockSemaphoreInfo(magic_semaphore);
387 ResetLinkedListIterator(magic_cache);
388 p=(
const MagicInfo *) GetNextValueInLinkedList(magic_cache);
389 if (magic == (
const unsigned char *) NULL)
391 UnlockSemaphoreInfo(magic_semaphore);
396 assert(p->offset >= 0);
397 if (((
size_t) (p->offset+p->length) <= length) &&
398 (memcmp(magic+p->offset,p->magic,p->length) == 0))
400 p=(
const MagicInfo *) GetNextValueInLinkedList(magic_cache);
403 (
void) InsertValueInLinkedList(magic_cache,0,
404 RemoveElementByValueFromLinkedList(magic_cache,p));
405 UnlockSemaphoreInfo(magic_semaphore);
438 #if defined(__cplusplus) || defined(c_plusplus)
442 static int MagicInfoCompare(
const void *x,
const void *y)
450 if (LocaleCompare((*p)->path,(*q)->path) == 0)
451 return(LocaleCompare((*p)->name,(*q)->name));
452 return(LocaleCompare((*p)->path,(*q)->path));
455 #if defined(__cplusplus) || defined(c_plusplus)
459 MagickExport
const MagicInfo **GetMagicInfoList(
const char *pattern,
474 assert(pattern != (
char *) NULL);
475 assert(number_aliases != (
size_t *) NULL);
476 if (IsEventLogging() != MagickFalse)
477 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
479 p=GetMagicInfo((
const unsigned char *) NULL,0,exception);
482 aliases=(
const MagicInfo **) AcquireQuantumMemory((
size_t)
483 GetNumberOfElementsInLinkedList(magic_cache)+1UL,
sizeof(*aliases));
484 if (aliases == (
const MagicInfo **) NULL)
489 LockSemaphoreInfo(magic_semaphore);
490 ResetLinkedListIterator(magic_cache);
491 p=(
const MagicInfo *) GetNextValueInLinkedList(magic_cache);
492 for (i=0; p != (
const MagicInfo *) NULL; )
494 if ((p->stealth == MagickFalse) &&
495 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
497 p=(
const MagicInfo *) GetNextValueInLinkedList(magic_cache);
499 UnlockSemaphoreInfo(magic_semaphore);
500 qsort((
void *) aliases,(
size_t) i,
sizeof(*aliases),MagicInfoCompare);
502 *number_aliases=(size_t) i;
536 #if defined(__cplusplus) || defined(c_plusplus)
540 static int MagicCompare(
const void *x,
const void *y)
548 return(LocaleCompare(p,q));
551 #if defined(__cplusplus) || defined(c_plusplus)
555 MagickExport
char **GetMagicList(
const char *pattern,
size_t *number_aliases,
570 assert(pattern != (
char *) NULL);
571 assert(number_aliases != (
size_t *) NULL);
572 if (IsEventLogging() != MagickFalse)
573 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
575 p=GetMagicInfo((
const unsigned char *) NULL,0,exception);
577 return((
char **) NULL);
578 aliases=(
char **) AcquireQuantumMemory((
size_t)
579 GetNumberOfElementsInLinkedList(magic_cache)+1UL,
sizeof(*aliases));
580 if (aliases == (
char **) NULL)
581 return((
char **) NULL);
582 LockSemaphoreInfo(magic_semaphore);
583 ResetLinkedListIterator(magic_cache);
584 p=(
const MagicInfo *) GetNextValueInLinkedList(magic_cache);
585 for (i=0; p != (
const MagicInfo *) NULL; )
587 if ((p->stealth == MagickFalse) &&
588 (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse))
589 aliases[i++]=ConstantString(p->name);
590 p=(
const MagicInfo *) GetNextValueInLinkedList(magic_cache);
592 UnlockSemaphoreInfo(magic_semaphore);
593 qsort((
void *) aliases,(
size_t) i,
sizeof(*aliases),MagicCompare);
594 aliases[i]=(
char *) NULL;
595 *number_aliases=(size_t) i;
621 MagickExport
const char *GetMagicName(
const MagicInfo *magic_info)
623 assert(magic_info != (
MagicInfo *) NULL);
624 assert(magic_info->signature == MagickCoreSignature);
625 if (IsEventLogging() != MagickFalse)
626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
627 return(magic_info->name);
653 static MagickBooleanType IsMagicCacheInstantiated(
ExceptionInfo *exception)
658 ActivateSemaphoreInfo(&magic_semaphore);
659 LockSemaphoreInfo(magic_semaphore);
661 magic_cache=AcquireMagicCache(MagicFilename,exception);
662 UnlockSemaphoreInfo(magic_semaphore);
664 return(magic_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
691 MagickExport MagickBooleanType ListMagicInfo(FILE *file,
709 if (file == (
const FILE *) NULL)
711 magic_info=GetMagicInfoList(
"*",&number_aliases,exception);
712 if (magic_info == (
const MagicInfo **) NULL)
715 path=(
const char *) NULL;
716 for (i=0; i < (ssize_t) number_aliases; i++)
718 if (magic_info[i]->stealth != MagickFalse)
720 if ((path == (
const char *) NULL) ||
721 (LocaleCompare(path,magic_info[i]->path) != 0))
723 if (magic_info[i]->path != (
char *) NULL)
724 (
void) FormatLocaleFile(file,
"\nPath: %s\n\n",magic_info[i]->path);
725 (void) FormatLocaleFile(file,
"Name Offset Target\n");
726 (void) FormatLocaleFile(file,
727 "-------------------------------------------------"
728 "------------------------------\n");
730 path=magic_info[i]->path;
731 (void) FormatLocaleFile(file,
"%s",magic_info[i]->name);
732 for (j=(ssize_t) strlen(magic_info[i]->name); j <= 9; j++)
733 (
void) FormatLocaleFile(file,
" ");
734 (void) FormatLocaleFile(file,
"%6ld ",(
long) magic_info[i]->offset);
735 if (magic_info[i]->target != (
char *) NULL)
740 for (j=0; magic_info[i]->target[j] !=
'\0'; j++)
741 if (isprint((
int) ((
unsigned char) magic_info[i]->target[j])) != 0)
742 (
void) FormatLocaleFile(file,
"%c",magic_info[i]->target[j]);
744 (
void) FormatLocaleFile(file,
"\\%03o",(
unsigned int)
745 ((
unsigned char) magic_info[i]->target[j]));
747 (void) FormatLocaleFile(file,
"\n");
750 magic_info=(
const MagicInfo **) RelinquishMagickMemory((
void *) magic_info);
754 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
785 static MagickBooleanType LoadMagicCache(
LinkedListInfo *cache,
const char *xml,
786 const char *filename,
const size_t depth,
ExceptionInfo *exception)
789 keyword[MaxTextExtent],
807 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
808 "Loading magic configure file \"%s\" ...",filename);
809 if (xml == (
char *) NULL)
813 token=AcquireString(xml);
814 extent=strlen(token)+MaxTextExtent;
815 for (q=(
char *) xml; *q !=
'\0'; )
820 (void) GetNextToken(q,&q,extent,token);
823 (void) CopyMagickString(keyword,token,MaxTextExtent);
824 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
829 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
830 (
void) GetNextToken(q,&q,extent,token);
833 if (LocaleNCompare(keyword,
"<!--",4) == 0)
838 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
839 (void) GetNextToken(q,&q,extent,token);
842 if (LocaleCompare(keyword,
"<include") == 0)
847 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
849 (void) CopyMagickString(keyword,token,MaxTextExtent);
850 (void) GetNextToken(q,&q,extent,token);
853 (void) GetNextToken(q,&q,extent,token);
854 if (LocaleCompare(keyword,
"file") == 0)
856 if (depth > MagickMaxRecursionDepth)
857 (void) ThrowMagickException(exception,GetMagickModule(),
858 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
865 GetPathComponent(filename,HeadPath,path);
867 (void) ConcatenateMagickString(path,DirectorySeparator,
869 if (*token == *DirectorySeparator)
870 (void) CopyMagickString(path,token,MaxTextExtent);
872 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
873 xml=FileToXML(path,~0UL);
874 if (xml != (
char *) NULL)
876 status&=LoadMagicCache(cache,xml,path,depth+1,
878 xml=(
char *) RelinquishMagickMemory(xml);
885 if (LocaleCompare(keyword,
"<magic") == 0)
890 magic_info=(
MagicInfo *) AcquireMagickMemory(
sizeof(*magic_info));
892 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
893 (void) memset(magic_info,0,
sizeof(*magic_info));
894 magic_info->path=ConstantString(filename);
895 magic_info->exempt=MagickFalse;
896 magic_info->signature=MagickCoreSignature;
901 if ((LocaleCompare(keyword,
"/>") == 0) ||
902 (LocaleCompare(keyword,
"</policy>") == 0))
904 status=AppendValueToLinkedList(cache,magic_info);
905 if (status == MagickFalse)
906 (void) ThrowMagickException(exception,GetMagickModule(),
907 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
912 (void) GetNextToken(q,(
const char **) NULL,extent,token);
915 (void) GetNextToken(q,&q,extent,token);
916 (void) GetNextToken(q,&q,extent,token);
922 if (LocaleCompare((
char *) keyword,
"name") == 0)
924 magic_info->name=ConstantString(token);
932 if (LocaleCompare((
char *) keyword,
"offset") == 0)
934 magic_info->offset=(MagickOffsetType) StringToLong(token);
942 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
944 magic_info->stealth=IsMagickTrue(token);
952 if (LocaleCompare((
char *) keyword,
"target") == 0)
963 length=strlen(token);
964 magic_info->target=ConstantString(token);
965 magic_info->magic=(
unsigned char *) ConstantString(token);
967 for (p=magic_info->target; *p !=
'\0'; )
972 if (isdigit((
int) ((
unsigned char) *p)) != 0)
977 *q++=(
unsigned char) strtol(p,&end,8);
979 magic_info->length++;
984 case 'b': *q=
'\b';
break;
985 case 'f': *q=
'\f';
break;
986 case 'n': *q=
'\n';
break;
987 case 'r': *q=
'\r';
break;
988 case 't': *q=
'\t';
break;
989 case 'v': *q=
'\v';
break;
990 case 'a': *q=
'a';
break;
991 case '?': *q=
'\?';
break;
992 default: *q=(
unsigned char) (*p);
break;
996 magic_info->length++;
1000 if (LocaleNCompare(p,
"&",5) == 0)
1001 (
void) CopyMagickString(p+1,p+5,length-magic_info->length);
1002 *q++=(
unsigned char) (*p++);
1003 magic_info->length++;
1013 token=(
char *) RelinquishMagickMemory(token);
1014 return(status != 0 ? MagickTrue : MagickFalse);
1036 MagickExport MagickBooleanType MagicComponentGenesis(
void)
1039 magic_semaphore=AllocateSemaphoreInfo();
1062 static void *DestroyMagicElement(
void *magic_info)
1068 if (p->exempt == MagickFalse)
1070 if (p->path != (
char *) NULL)
1071 p->path=DestroyString(p->path);
1072 if (p->name != (
char *) NULL)
1073 p->name=DestroyString(p->name);
1074 if (p->target != (
char *) NULL)
1075 p->target=DestroyString(p->target);
1076 if (p->magic != (
unsigned char *) NULL)
1077 p->magic=(
unsigned char *) RelinquishMagickMemory(p->magic);
1079 p=(
MagicInfo *) RelinquishMagickMemory(p);
1080 return((
void *) NULL);
1083 MagickExport
void MagicComponentTerminus(
void)
1086 ActivateSemaphoreInfo(&magic_semaphore);
1087 LockSemaphoreInfo(magic_semaphore);
1089 magic_cache=DestroyLinkedList(magic_cache,DestroyMagicElement);
1090 UnlockSemaphoreInfo(magic_semaphore);
1091 DestroySemaphoreInfo(&magic_semaphore);