File: | /home/joel/rtems-4.11-work/build/rtems/c/src/../../cpukit/posix/src/aio_write.c |
Location: | line 64, 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_write.c,v 1.4 2010/08/24 06:46:29 ralf Exp $ | ||
9 | */ | ||
10 | |||
11 | |||
12 | #if HAVE_CONFIG_H1 | ||
13 | #include "config.h" | ||
14 | #endif | ||
15 | |||
16 | #include <aio.h> | ||
17 | #include <errno(*__errno_location ()).h> | ||
18 | #include <fcntl.h> | ||
19 | #include <rtems/posix/aio_misc.h> | ||
20 | #include <rtems/system.h> | ||
21 | #include <rtems/seterr.h> | ||
22 | #include <stdlib.h> | ||
23 | |||
24 | /* | ||
25 | * aio_write | ||
26 | * | ||
27 | * Asynchronous write to a file | ||
28 | * | ||
29 | * Input parameters: | ||
30 | * aiocbp - asynchronous I/O control block | ||
31 | * | ||
32 | * Output parameters: | ||
33 | * -1 - request could not be enqueued | ||
34 | * - FD not opened for write | ||
35 | * - invalid aio_reqprio or aio_offset or | ||
36 | * aio_nbytes | ||
37 | * - not enough memory | ||
38 | * 0 - otherwise | ||
39 | */ | ||
40 | |||
41 | int | ||
42 | aio_write (struct aiocb *aiocbp) | ||
43 | { | ||
44 | rtems_aio_request *req; | ||
45 | int mode; | ||
46 | |||
47 | mode = fcntl (aiocbp->aio_fildes, F_GETFL3); | ||
48 | if (!(((mode & O_ACCMODE0003) == O_WRONLY01) || ((mode & O_ACCMODE0003) == O_RDWR02))) | ||
| |||
49 | 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); | ||
50 | |||
51 | if (aiocbp->aio_reqprio < 0 || aiocbp->aio_reqprio > AIO_PRIO_DELTA_MAX20) | ||
| |||
52 | 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); | ||
53 | |||
54 | if (aiocbp->aio_offset < 0) | ||
| |||
55 | 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); | ||
56 | |||
57 | req = malloc (sizeof (rtems_aio_request)); | ||
58 | if (req == NULL((void *)0)) | ||
| |||
59 | 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); | ||
60 | |||
61 | req->aiocbp = aiocbp; | ||
62 | req->aiocbp->aio_lio_opcode = LIO_WRITE2; | ||
63 | |||
64 | return rtems_aio_enqueue (req); | ||
| |||
65 | } |