delete_and_reload_printers() unconditionally calls lp_killservice()
to destroy autoloaded printer services that are no longer in the
printer list. If any active connection is still using the printer
service number, the destroyed service can cause a NULL pointer
dereference on subsequent requests.
Guard the call with connections_snum_used() so the service is only
freed when no connections are using it.
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14978
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: David Mulder <dmulder@samba.org>
/* check printer, but avoid removing non-autoloaded printers */
if (lp_autoloaded(snum) &&
- !printer_list_printername_exists(pname)) {
+ !printer_list_printername_exists(pname) &&
+ !connections_snum_used(NULL, snum)) {
lp_killservice(snum);
}
}