Windows: replace strdup with xdr_alloc in callback processing
authorJeffrey Altman <jaltman@your-file-system.com>
Wed, 28 Dec 2011 22:07:01 +0000 (17:07 -0500)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Sat, 31 Dec 2011 21:16:51 +0000 (13:16 -0800)
The CRT allocator cannot be used for memory that will be freed
by afsrpc.dll.  Use xdr_alloc() instead.

Change-Id: Idd33710c225d58b4e6eba0bfdb2f8b3282996258
Reviewed-on: http://gerrit.openafs.org/6439
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>

src/WINNT/afsd/cm_callback.c

index c2408e4..d1aa1e0 100644 (file)
@@ -1157,15 +1157,21 @@ GetCellCommon(afs_int32 a_cellnum, char **a_name, serverList *a_hosts)
     afs_int32 sn;
     cm_cell_t * cellp;
     cm_serverRef_t * serverRefp;
+    size_t len;
 
     cellp = cm_FindCellByID(a_cellnum, CM_FLAG_NOPROBE);
     if (!cellp) {
-        *a_name = strdup("");
+        *a_name = (char *)xdr_alloc(sizeof(char));
+        if (*a_name)
+            *a_name = '\0';
         return 0;
     }
 
     lock_ObtainRead(&cm_serverLock);
-    *a_name = strdup(cellp->name);
+    len = strlen(cellp->name)+1;
+    *a_name = (char *)xdr_alloc(len);
+    if (*a_name)
+        memcpy(*a_name, cellp->name, len);
 
     for ( sn = 0, serverRefp = cellp->vlServersp;
           sn < AFSMAXCELLHOSTS && serverRefp;
@@ -1408,6 +1414,7 @@ int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
     struct rx_peer *peerp;
     unsigned long host = 0;
     unsigned short port = 0;
+    size_t len;
 
     if (cm_shutdown)
         return 1;
@@ -1421,7 +1428,10 @@ int SRXAFSCB_GetLocalCell(struct rx_call *callp, char **a_name)
              ntohl(host), ntohs(port));
 
     if (cm_data.rootCellp) {
-        t_name = strdup(cm_data.rootCellp->name);
+        len = strlen(cm_data.rootCellp->name) + 1;
+        t_name = (char *)xdr_alloc(len);
+        if (t_name)
+            memcpy(t_name, cm_data.rootCellp->name, len);
     } else {
        t_name = (char *)xdr_alloc(1);
        t_name[0] = '\0';