1 /** 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <malloc.h> 17 #include <pthread.h> 18 #include <stdbool.h> 19 #include "gwp_asan.h" 20 #include "test.h" 21 process_task()22int process_task() 23 { 24 void *ptr = malloc(20); 25 if (!ptr) { 26 return 0; 27 } 28 free(ptr); 29 return 0; 30 } 31 32 // Test whether it's ok to open gwp_asan in the fork scenario. main()33int main() 34 { 35 may_init_gwp_asan(true); 36 pid_t pid = fork(); 37 if (pid < 0) { 38 t_error("FAIL fork failed."); 39 } else if (pid == 0) { // child process 40 return process_task(); 41 } else { // parent process 42 return process_task(); 43 } 44 return t_status; 45 }