[ofw] [PATCH][REPOST] opensm/libvendor/winosm_common.c: Better failure handling in strdup_expand and Fopen
Smith, Stan
stan.smith at intel.com
Wed Apr 11 17:05:59 PDT 2012
Done in upcoming opensm 3.3.13 commit (Thursday).
Thanks,
Stan.
>-----Original Message-----
>From: Hal Rosenstock [mailto:hal at dev.mellanox.co.il]
>Sent: Wednesday, April 11, 2012 7:34 AM
>To: Smith, Stan
>Cc: ofw at lists.openfabrics.org
>Subject: [PATCH][REPOST] opensm/libvendor/winosm_common.c: Better failure handling in strdup_expand and Fopen
>
>
>Return NULL when (underlying) malloc fails
>
>Signed-off-by: Hal Rosenstock <hal at mellanox.com>
>---
>Index: libvendor/winosm_common.c
>===================================================================
>--- libvendor/winosm_common.c (revision 3395)
>+++ libvendor/winosm_common.c (working copy)
>@@ -52,9 +52,12 @@
> char *fname;
>
> fname = strdup_expand(filename);
>- pFile = fopen(fname,mode);
>- free(fname);
>- return pFile;
>+ if (fname) {
>+ pFile = fopen(fname,mode);
>+ free(fname);
>+ return pFile;
>+ }
>+ return NULL;
> }
>
> #define OSM_MAX_LOG_NAME_SIZE 512
>@@ -177,7 +180,7 @@
>
>
> /*
>- * Like _strdup() with Environment varible expansion.
>+ * Like _strdup() with Environment variable expansion.
> * Example: str '%windir%\temp\osm.log' --> 'C:\windows\temp\osm.log'
> * Multiple Env vars are supported.
> */
>@@ -188,6 +191,8 @@
> char p_env[80];
>
> str = _strdup(base);
>+ if (!str)
>+ return str;
>
> while( (s = strchr(str,'%')) )
> {
>@@ -203,10 +208,12 @@
> return str;
>
> xs = (char*)malloc(strlen(str)+strlen(es));
>- for(rc=str,n=xs; rc < (s-1);rc++) *n++ = *rc;
>- *n='\0';
>- strcat(n,es);
>- strcat(n,(p+1));
>+ if (xs) {
>+ for(rc=str,n=xs; rc < (s-1);rc++) *n++ = *rc;
>+ *n='\0';
>+ strcat(n,es);
>+ strcat(n,(p+1));
>+ }
> free(str);
> str = xs;
> }
More information about the ofw
mailing list