author | Florian Forster <octo@collectd.org> | |
Sun, 14 May 2017 06:24:51 +0000 (08:24 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Sun, 14 May 2017 06:31:22 +0000 (08:31 +0200) | ||
commit | 867e977f14bdb55dd2c727a8b9b5f6aaac41e558 | |
tree | 0e6cb7c6d721f301830752ce68ed9315575e53fb | tree | snapshot |
parent | c3e2a69bd600fa4c4a9d4603094f39ea81c11116 | commit | diff |
perl plugin: Fix potential double-free.
The av2notification_meta() function updated it's parameter by doing
(*m) = malloc();
Afterwards, if an error occurred, it would call `free(*m);` and (potentially)
return, leaving an invalid pointer stored in `m`. The caller would then try to
free the returned pointer because it was non-NULL.
This patch fixes this by doing several code cleanups:
* The meta argument is not updated unnecessarily. Instead, a local variable
is allocated and used within the loop and only on success is the return
pointer updated.
* Introduce additional local variables instead of re-using the `tmp` variable
multiple times.
* Name the variable pointing to the end of the linked list appropriately
`tail` and remove one level of indirection. Reading code that is using
pointers to pointers is unnecessarily hard.
The av2notification_meta() function updated it's parameter by doing
(*m) = malloc();
Afterwards, if an error occurred, it would call `free(*m);` and (potentially)
return, leaving an invalid pointer stored in `m`. The caller would then try to
free the returned pointer because it was non-NULL.
This patch fixes this by doing several code cleanups:
* The meta argument is not updated unnecessarily. Instead, a local variable
is allocated and used within the loop and only on success is the return
pointer updated.
* Introduce additional local variables instead of re-using the `tmp` variable
multiple times.
* Name the variable pointing to the end of the linked list appropriately
`tail` and remove one level of indirection. Reading code that is using
pointers to pointers is unnecessarily hard.
src/perl.c | diff | blob | history |