/src/FreeRDP/winpr/libwinpr/crt/memory.c
Line | Count | Source |
1 | | /** |
2 | | * WinPR: Windows Portable Runtime |
3 | | * Memory Allocation |
4 | | * |
5 | | * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> |
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 | | #include <winpr/config.h> |
21 | | |
22 | | #include <winpr/crt.h> |
23 | | |
24 | | /* Memory Allocation: http://msdn.microsoft.com/en-us/library/hk1k7x6x.aspx */ |
25 | | /* Memory Management Functions: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366781/ */ |
26 | | |
27 | | #ifndef _WIN32 |
28 | | |
29 | | PVOID SecureZeroMemory(PVOID ptr, size_t cnt) |
30 | 0 | { |
31 | 0 | volatile BYTE* p = ptr; |
32 | |
|
33 | 0 | while (cnt--) |
34 | 0 | { |
35 | 0 | *p = 0; |
36 | 0 | p++; |
37 | 0 | } |
38 | |
|
39 | 0 | return ptr; |
40 | 0 | } |
41 | | |
42 | | #endif |
43 | | |
44 | | void winpr_zfree(char* str) |
45 | 456k | { |
46 | 456k | if (str) |
47 | 46.8k | { |
48 | 46.8k | char* cur = str; |
49 | 1.12M | while (*cur != '\0') |
50 | 1.07M | *cur++ = '\0'; |
51 | 46.8k | } |
52 | 456k | free(str); |
53 | 456k | } |
54 | | |
55 | | void winpr_znfree(void* data, size_t len) |
56 | 0 | { |
57 | 0 | WINPR_ASSERT(data || (len == 0)); |
58 | 0 | if (data) |
59 | 0 | memset(data, 0, len); |
60 | 0 | free(data); |
61 | 0 | } |