edwardcapriolo commented on PR #8177:
URL: https://github.com/apache/hadoop/pull/8177#issuecomment-3746776613

   @cnauroth 
   
   Interestingly what I believe i have found is that your must deep copy these 
objects.  What I observe is repeated calls to the method changes the objects. 
Something about the buffer sizing of the old code wasn't hitting the edge case. 
   
   For some confirmation I asked google: multipe callsto getpwnam_r to create 
array of users.
   It provided code that was doing a deep copy of the objects, and this 
explanation.
   
   Key Concepts
   
       Reentrancy: getpwnam_r() is thread-safe because the caller provides the 
memory (buffer) where the data is stored.
       Persistent Storage: To build an array, you cannot just store pointers to 
the temporary pwd struct used inside the loop. You must make a deep copy of the 
data (the UserEntry struct and the strings within it) into a new, stable memory 
location that persists across loop iterations.
       Error Handling: Check the return value (status) and the result pointer 
to differentiate between an error condition and a "user not found" scenario.
       Memory Management: Dynamic memory allocation (malloc, strdup) requires 
explicit deallocation using free to prevent memory leaks
   
   
   This is exactly the conclusion I had come to that we need to deep copy this 
object because the second call to the method alters the state of the first 
struct.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to