File: | /home/joel/rtems-4.11-work/build/rtems/c/src/../../cpukit/posix/src/aio_fsync.c |
Location: | line 61, column 3 |
Description: | Allocated memory never released. Potential memory leak |
1 | /* | ||
2 | * Copyright 2010, Alin Rus <alin.codejunkie@gmail.com> | ||
3 | * | ||
4 | * The license and distribution terms for this file may be | ||
5 | * found in the file LICENSE in this distribution or at | ||
6 | * http://www.rtems.com/license/LICENSE. | ||
7 | * | ||
8 | * $Id: aio_fsync.c,v 1.3 2010/08/20 09:08:05 ralf Exp $ | ||
9 | */ | ||
10 | |||
11 | #if HAVE_CONFIG_H1 | ||
12 | #include "config.h" | ||
13 | #endif | ||
14 | |||
15 | #include <aio.h> | ||
16 | #include <errno(*__errno_location ()).h> | ||
17 | #include <stdlib.h> | ||
18 | #include <rtems/posix/aio_misc.h> | ||
19 | #include <rtems/system.h> | ||
20 | #include <rtems/seterr.h> | ||
21 | |||
22 | /* | ||
23 | * aio_fsync | ||
24 | * | ||
25 | * Asynchronous file synchronization | ||
26 | * | ||
27 | * Input parameters: | ||
28 | * op - O_SYNC | ||
29 | * aiocbp - asynchronous I/O control block | ||
30 | * | ||
31 | * Output parameters: | ||
32 | * -1 - request could not pe enqueued | ||
33 | * - FD not opened for write | ||
34 | * - not enough memory | ||
35 | * - op is not O_SYNC | ||
36 | * 0 - otherwise | ||
37 | */ | ||
38 | |||
39 | int aio_fsync( | ||
40 | int op, | ||
41 | struct aiocb *aiocbp | ||
42 | ) | ||
43 | { | ||
44 | rtems_aio_request *req; | ||
45 | int mode; | ||
46 | |||
47 | if (op != O_SYNC04010000) | ||
| |||
48 | rtems_aio_set_errno_return_minus_one (EINVAL, aiocbp)do { (aiocbp)->error_code = (22); (aiocbp)->return_value = -1; do { (*__errno_location ()) = (22); return -1; } while (0);} while(0); | ||
49 | |||
50 | mode = fcntl (aiocbp->aio_fildes, F_GETFL3); | ||
51 | if (!(((mode & O_ACCMODE0003) == O_WRONLY01) || ((mode & O_ACCMODE0003) == O_RDWR02))) | ||
| |||
52 | rtems_aio_set_errno_return_minus_one (EBADF, aiocbp)do { (aiocbp)->error_code = (9); (aiocbp)->return_value = -1; do { (*__errno_location ()) = (9); return -1; } while( 0);} while(0); | ||
53 | |||
54 | req = malloc (sizeof (rtems_aio_request)); | ||
55 | if (req == NULL((void *)0)) | ||
| |||
56 | rtems_aio_set_errno_return_minus_one (EAGAIN, aiocbp)do { (aiocbp)->error_code = (11); (aiocbp)->return_value = -1; do { (*__errno_location ()) = (11); return -1; } while (0);} while(0); | ||
57 | |||
58 | req->aiocbp = aiocbp; | ||
59 | req->aiocbp->aio_lio_opcode = LIO_SYNC3; | ||
60 | |||
61 | return rtems_aio_enqueue (req); | ||
| |||
62 | |||
63 | } |