- len = orig->namelen;
- if (orig->name) {
- dupe->name = PerlMemShared_malloc(len + 1);
- Copy(orig->name, dupe->name, len, char);
- ((char *) dupe->name)[len] = '\0';
- } else {
- dupe->name = NULL;
- }
- dupe->namelen = len;
-
- len = orig->protolen;
- if (orig->proto) {
- dupe->proto = PerlMemShared_malloc(len + 1);
- Copy(orig->proto, dupe->proto, len, char);
- ((char *) dupe->proto)[len] = '\0';
- } else {
- dupe->proto = NULL;
- }
- dupe->protolen = len;
+ dupe->name = so_strndup(orig->name, orig->namelen);
+ dupe->namelen = orig->namelen;
+
+ dupe->proto = so_strndup(orig->proto, orig->protolen);
+ dupe->protolen = orig->protolen;