Return NULL when (underlying) malloc fails 

Signed-off-by: Hal Rosenstock <[email protected]>
---
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;
        }
_______________________________________________
ofw mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/ofw

Reply via email to