Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d599b8e

Browse files
committedMar 10, 2025
UTIL: sss_parse_internal_fqname() optimization
'tmp_ctx' was removed as it wasn't really used anyway. Code could be changed to make a real use of 'tmp_ctx': to avoid touching '_dom_name' output arg if update of '_shortname' fails. But this is quite unrealistic case and function is in a hot path, so better to aboid unneeded memory manipulations.
1 parent be7e191 commit d599b8e

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed
 

‎src/util/usertools.c

+9-28
Original file line numberDiff line numberDiff line change
@@ -608,54 +608,35 @@ errno_t sss_parse_internal_fqname(TALLOC_CTX *mem_ctx,
608608
char **_shortname,
609609
char **_dom_name)
610610
{
611-
errno_t ret;
612-
char *separator;
613-
char *shortname = NULL;
614-
char *dom_name = NULL;
611+
const char *separator;
615612
size_t shortname_len;
616-
TALLOC_CTX *tmp_ctx;
617613

618614
if (fqname == NULL) {
619615
return EINVAL;
620616
}
621617

622-
tmp_ctx = talloc_new(NULL);
623-
if (tmp_ctx == NULL) {
624-
return ENOMEM;
625-
}
626-
627618
separator = strrchr(fqname, '@');
628619
if (separator == NULL || *(separator + 1) == '\0' || separator == fqname) {
629620
/*The name does not contain name or domain component. */
630-
ret = ERR_WRONG_NAME_FORMAT;
631-
goto done;
621+
return ERR_WRONG_NAME_FORMAT;
632622
}
633623

634624
if (_dom_name != NULL) {
635-
dom_name = talloc_strdup(tmp_ctx, separator + 1);
636-
if (dom_name == NULL) {
637-
ret = ENOMEM;
638-
goto done;
625+
*_dom_name = talloc_strdup(mem_ctx, separator + 1);
626+
if (*_dom_name == NULL) {
627+
return ENOMEM;
639628
}
640-
641-
*_dom_name = talloc_steal(mem_ctx, dom_name);
642629
}
643630

644631
if (_shortname != NULL) {
645632
shortname_len = strlen(fqname) - strlen(separator);
646-
shortname = talloc_strndup(tmp_ctx, fqname, shortname_len);
647-
if (shortname == NULL) {
648-
ret = ENOMEM;
649-
goto done;
633+
*_shortname = talloc_strndup(mem_ctx, fqname, shortname_len);
634+
if (*_shortname == NULL) {
635+
return ENOMEM;
650636
}
651-
652-
*_shortname = talloc_steal(mem_ctx, shortname);
653637
}
654638

655-
ret = EOK;
656-
done:
657-
talloc_free(tmp_ctx);
658-
return ret;
639+
return EOK;
659640
}
660641

661642
/* Creates internal fqname in format shortname@domname.

0 commit comments

Comments
 (0)
Please sign in to comment.