nqminds / edgesec

Secure router - reference implementation
https://edgesec.info
MIT License
6 stars 1 forks source link

Fix a potential double-`free()` in `run_ctl()` #530

Closed aloisklink closed 1 year ago

aloisklink commented 1 year ago

Skip free()-ing the eloop parameter in run_ctl(). If this parameter is passed in to run_ctl(), we should let the caller free() it instead of us.

This also fixes a memory leak in test_edgesec.c.


I've also simplified the run_ctl() cleanup code by merging the success and goto run_engine_fail code.

The only two differences between the two was:

  1. the success bit return 0, while the failure bit return -1;, which was easy to fix.
  2. On the success bit, this following line of code was always call: https://github.com/nqminds/edgesec/blob/b722d492217a769f0e86904fb0ceac7f92212940/src/runctl.c#L584 However, on the goto run_engine_fail branch, it was hidden behind an if (.. != NULL) branch: https://github.com/nqminds/edgesec/blob/b722d492217a769f0e86904fb0ceac7f92212940/src/runctl.c#L608-L610
codecov[bot] commented 1 year ago

Codecov Report

Merging #530 (b26a67b) into main (a5bb42e) will increase coverage by 0.07%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #530      +/-   ##
==========================================
+ Coverage   53.57%   53.64%   +0.07%     
==========================================
  Files         144      144              
  Lines       20005    19993      -12     
==========================================
+ Hits        10717    10725       +8     
+ Misses       9288     9268      -20     
Impacted Files Coverage Δ
src/runctl.c 57.86% <100.00%> (+3.93%) :arrow_up:
tests/test_edgesec.c 97.87% <100.00%> (+0.01%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.