Guest User

Untitled

a guest
Jan 1st, 2015
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 KB | None | 0 0
  1. General impressions
  2. ~~~~~~~~~~~~~~~~~~~
  3.  
  4. Many (all ?) of the symbols exposed in library functions are systemd
  5. shims and unused within the codebase.
  6.  
  7. Would be nice to have a configure switch to enable/disable building
  8. of the 'systemd shim' portion of LoginKit.
  9.  
  10. LoginKit should probably bring it's own philosophy about how it's
  11. really intended to be used, provide some library API where it's needed
  12. and have the systemd APIs as optional at build/install time.
  13.  
  14. __attribute__((visibility ("default"))) is used in many places, what
  15. is the reason for this ?
  16.  
  17. It seems just convoluted, globally defined symbols are visible by
  18. default in any library, why the extra compiler hint ?
  19.  
  20.  
  21. common
  22. ~~~~~~
  23.  
  24. common/bus.c
  25. ~~~~~~~~~~~~
  26.  
  27. This seems to get the GDBusConnection for the system bus which generally stays alive
  28. for the calling program's lifetime, in places you have a library destructor which
  29. explicitly closes the bus.
  30.  
  31. I would suggest using the GOnce pattern here, so that the bus is simply accquired the first
  32. time to resolve the bus and perhaps move that library destructor code to the same place.
  33.  
  34.  
  35. loginkit-daemon
  36. ~~~~~~~~~~~~~~~
  37.  
  38. Not much to say about this directory, mostly systemd shim stuff.
  39.  
  40.  
  41. loginkit-login
  42. ~~~~~~~~~~~~~~
  43.  
  44. Watch the memory in this directory.
  45. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  46.  
  47. pid.c: get_session_by_pid() returns an object path string allocated by glib
  48. which needs to be freed with g_free()
  49.  
  50. sd_pid_get_session() does: *session = strdup (*session) and leaks
  51. the string returned by get_session_by_pid().
  52.  
  53. sd_pid_get_owner_uid() and sd_pid_get_machine_name() also
  54. leaks the session path string.
  55.  
  56. session.c: get_seat() Similar issues as get_session_by_pid(), simply leaking
  57. glib allocated data with *seat = strdup (*seat).
  58.  
  59.  
  60. For the above issues, suggest using the special '&' syntax for getting the
  61. string from the variant without any memory allocation, before unreffing
  62. the variant itself.
  63.  
  64. For example, in get_seat() you could have:
  65.  
  66. /* Get a pointer to the memory holding the string in the variant */
  67. g_variant_get (reply, "(&o)", seat);
  68.  
  69. /* Allocate a copy on glibc's memory heap */
  70. *seat = strdup (*seat);
  71.  
  72. /* Now safely free the variant */
  73. g_variant_unref (reply);
  74.  
  75.  
  76. seat.c: sd_seat_get_sessions()
  77.  
  78. There are multiple memory management issues here:
  79.  
  80. a.) Fetch the count at the beggining as you do to determine the size
  81. of the returned vectors/arrays.
  82.  
  83. b.) Use the while loop as documented in g_variant_iter_loop(), otherwise
  84. you will invariably leak the last value as g_variant_iter_loop() does
  85. not have a chance to free it for you when hitting the last item.
  86.  
  87. c.) You are assuming that the string pointer handed to you in g_variant_iter_loop()
  88. is actually given to you, but it's not - as g_variant_iter_loop() documentation
  89. specifies that you need not free the values passed between iterations.
  90.  
  91. This is actually practical for you, as you will want a copy on glibc's heap
  92.  
  93. d.) In the case of an error encountered in the loop, you free the 'sessions'
  94. vector but fail to free the allocated strings in that vector.
  95.  
  96. e.) You need to ensure the memory returned from this function is on the correct
  97. heap, right now you are returning memory allocated by glib, which will, I assume,
  98. later be freed with glibc functions like 'free()'.
  99.  
  100. Note that:
  101.  
  102. char *ptr = g_strdup ("pony");
  103. free (ptr);
  104.  
  105. Is incorrect and will cause memory corruption and faults.
  106.  
  107. You need to allocate those vectors before the loop with glibc functions
  108. and ensure that the strings you assign are copied with strdup() as you
  109. already do elsewhere.
  110.  
  111.  
  112. loginkit
  113. ~~~~~~~~
  114.  
  115. More memory related issues around here...
  116.  
  117. power.c: handle_can() returns allocated string which is never freed.
  118.  
  119. I didnt look through all the various files here, possibly there are other
  120. memory management related issues.
  121.  
  122. loginkitd.c: I dont think you want or need to be using the convinence
  123. bus_get() API here.
  124.  
  125. Instead, you actually *have* the bus when on_name_acquired()
  126. and on_name_lost() is called - use that bus to export and
  127. unexport your interface skeleton and to subscribe and
  128. unsubscribe from signals.
  129.  
  130. I'm also unsure if you want to quit the mainloop based on
  131. losing the bus name.
  132.  
  133. Instead I would probably use g_unix_signal_add_full()
  134. to subscribe to the SIGTERM signal and then explicitly
  135. unown the bus name, causing everything to come down,
  136. and then eventually quit.
Advertisement
Add Comment
Please, Sign In to add comment