MITHILESH MATTAPALLI commented on a discussion on 
cpukit/libblock/src/flashdisk.c: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/903#note_139729

 >       */
 >      fd->copy_buffer = malloc (c->block_size);
 >      if (!fd->copy_buffer)
 > -      return RTEMS_NO_MEMORY;
 > +    {
 > +      sc = RTEMS_NO_MEMORY;
 > +      goto error_cleanup;

The cleanup logic required here is non-trivial: it must iterate over all 
previously initialized devices (minor \> 0), unlink them from the file system, 
destroy their mutexes, and free multiple nested pointers (segments, devices, 
blocks, copy_buffer) to prevent memory leaks and system crashes.

Since there are multiple distinct allocation points that can fail (copy_buffer, 
blocks, devices, segments), avoiding goto would require duplicating this 
extensive cleanup logic inside every single error check. That would 
significantly increase code size and maintenance burden. Using goto 
error_cleanup centralizes the teardown logic (DRY), keeping the initialization 
flow linear and readable.

-- 
View it on GitLab: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/903#note_139729
You're receiving this email because of your account on gitlab.rtems.org.


_______________________________________________
bugs mailing list
[email protected]
http://lists.rtems.org/mailman/listinfo/bugs

Reply via email to