lib: param: Remove the last external use of global_iconv_handle by calling the utilit...
authorJeremy Allison <jra@samba.org>
Tue, 11 Apr 2017 22:57:28 +0000 (15:57 -0700)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 18 Apr 2017 09:47:17 +0000 (11:47 +0200)
Add an error check.

This *looks* like a logic change, but it is not.

The only change is the addition of the error return check.

The reason is that the changed function, reload_charcnv(),
is the *only* function that sets lp_ctx->iconv_handle. And
it does so just before setting global_iconv_handle = lp_ctx->iconv_handle.

Calling the utility function reinit_iconv_handle()
instead merely sets global_iconv_handle first, then
assigns it (as the return) to lp_ctx->iconv_handle.

So all this is doing is reversing the order of
setting global_iconv_handle and lp_ctx->iconv_handle
to the same thing.

Even the removal of the lines:

-       struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle
-       if (old_ic == NULL) {
-               old_ic = global_iconv_handle;

has no effect, as remember that lp_ctx->iconv_handle
is only ever set to the same value as global_iconv_handle,
and once this function has been run once, lp_ctx->iconv_handle != NULL.

This allows us finally to make global_iconv_handle private
to the C source file that defines it.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/param/loadparm.c

index 5b5543c4a2a742a5efc88a907e5240aa4e603e7a..d7287ab6cd63899a844d95f38675a21ae1d4d2e1 100644 (file)
@@ -3356,20 +3356,17 @@ struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
 
 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
 {
-       struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
        if (!lp_ctx->global) {
                return;
        }
 
-       if (old_ic == NULL) {
-               old_ic = global_iconv_handle;
+       lp_ctx->iconv_handle =
+               reinit_iconv_handle(lp_ctx,
+                                   lpcfg_dos_charset(lp_ctx),
+                                   lpcfg_unix_charset(lp_ctx));
+       if (lp_ctx->iconv_handle == NULL) {
+               smb_panic("reinit_iconv_handle failed");
        }
-       lp_ctx->iconv_handle = smb_iconv_handle_reinit(lp_ctx,
-                                       lpcfg_dos_charset(lp_ctx),
-                                       lpcfg_unix_charset(lp_ctx),
-                                       true,
-                                       old_ic);
-       global_iconv_handle = lp_ctx->iconv_handle;
 }
 
 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)