Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak in udp-queue-natives #12

Open
JellyBrick opened this issue Apr 26, 2020 · 0 comments
Open

Possible memory leak in udp-queue-natives #12

JellyBrick opened this issue Apr 26, 2020 · 0 comments

Comments

@JellyBrick
Copy link

JellyBrick commented Apr 26, 2020

With gcc-11 -fanalyzer (GCC 11 Static analysis)

jda-nas/udp-queue-natives/udpqueue/udpqueue.c:236:16: warning: leak ofbytes’ [CWE-401] [-Wanalyzer-malloc-leak]
  236 |         return result;
      |                ^~~~~~
  ‘manager_queue_packet’: events 1-6
    |
    |  218 | static bool manager_queue_packet(queue_manager_t* manager, uint64_t key, const char* address, int32_t port, void* data,
    |      |             ^~~~~~~~~~~~~~~~~~~~
    |      |             |
    |      |             (1) entry tomanager_queue_packet’
    |......
    |  221 |         uint8_t* bytes = malloc(data_length);
    |      |                          ~~~~~~~~~~~~~~~~~~~
    |      |                          |
    |      |                          (2) allocated here
    |  222 |         if (bytes == NULL) {
    |      |            ~ 
    |      |            |
    |      |            (3) assumingbytesis non-NULL
    |      |            (4) following ‘false’ branch (whenbytesis non-NULL)...
    |......
    |  226 |         memcpy(bytes, data, data_length);
    |      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |         |
    |      |         (5) ...to here
    |......
    |  229 |         bool result = manager_queue_packet_locked(manager, key, address, port, bytes, data_length, explicit_socket);
    |      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                       |
    |      |                       (6) callingmanager_queue_packet_lockedfrommanager_queue_packet’
    |
    +-->manager_queue_packet_locked’: events 7-9
           |
           |  178 | static bool manager_queue_packet_locked(queue_manager_t* manager, uint64_t key, const char* address, int32_t port,
           |      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
           |      |             |
           |      |             (7) entry tomanager_queue_packet_locked’
           |......
           |  187 |         else if (!existed) {
           |      |                 ~
           |      |                 |
           |      |                 (8) following ‘false’ branch...
           |......
           |  207 |         if (queue->buffer_size >= queue->buffer_capacity) {
           |      |             ~~~~~~~~~~~~~~~~~~
           |      |                  |
           |      |                  (9) ...to here
           |
    <------+
    |
  ‘manager_queue_packet’: events 10-13
    |
    |  229 |         bool result = manager_queue_packet_locked(manager, key, address, port, bytes, data_length, explicit_socket);
    |      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                       |
    |      |                       (10) returning tomanager_queue_packetfrommanager_queue_packet_locked’
    |......
    |  232 |         if (!result) {
    |      |            ~           
    |      |            |
    |      |            (11) following ‘false’ branch...
    |......
    |  236 |         return result;
    |      |                ~~~~~~  
    |      |                |
    |      |                (12) ...to here
    |      |                (13) ‘bytesleaks here; was allocated at (2)
    |
@JellyBrick JellyBrick changed the title Mem-leak in udpqueue-natives Mem-leak in udp-queue-natives Apr 26, 2020
@JellyBrick JellyBrick changed the title Mem-leak in udp-queue-natives Memory leak in udp-queue-natives Apr 26, 2020
@JellyBrick JellyBrick changed the title Memory leak in udp-queue-natives Possible memory leak in udp-queue-natives May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant