1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // Try to create a resource leak in the server by opening a stream and then not closing it.
18 // Return 0 if the stream opened, 1 if it failed.
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <aaudio/AAudio.h>
23 
main(int argc,char ** argv)24 int main(int argc, char **argv)
25 {
26     (void)argc; // unused
27     (void)argv; // unused
28 
29     aaudio_result_t result = AAUDIO_OK;
30     AAudioStreamBuilder *aaudioBuilder = nullptr;
31     AAudioStream *aaudioStream = nullptr;
32 
33     result = AAudio_createStreamBuilder(&aaudioBuilder);
34     if (result != AAUDIO_OK) {
35         goto finish;
36     }
37 
38     // Create an AAudioStream using the Builder.
39     result = AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream);
40     if (result != AAUDIO_OK) {
41         printf("ERROR could not open AAudio stream, %d\n", result);
42         goto finish;
43     } else {
44         printf("AAudio stream opened successfully.\n");
45     }
46 
47     printf("Exit without closing the stream!\n");
48 
49 finish:
50     return (result != AAUDIO_OK) ? EXIT_FAILURE : EXIT_SUCCESS;
51 }
52 
53