Commits

William Giokas committed da19aba

Add SFREE macro

Safe FREE: Check if value exists. If not, do nothing, else free it.

Signed-off-by: William Giokas <1007380@gmail.com>

Comments (0)

Files changed (3)

             avgs   = loadavg();
             temp   = gettemperature(TEMP_SENSOR_PATH, TEMP_SENSOR_UNIT);
             batt   = getbattery(BATT_PATH);
-            if(!temp) free(temp);
+            SFREE(temp);
         }
         /* Update every second */
         net    = get_netusage(net_device_up);
         /* Format of display */
         status = smprintf("%s (%s) | %s [%s] T %s | %s",
                 net, ipaddr, batt, avgs, temp, time);
-        if(!ipaddr) free(ipaddr);
+        SFREE(ipaddr)
         free(net);
 
         if(tostatusbar == 0)

include/battery.h

     else
         ret = smprintf("%s: %.2lf%% %02d:%02d:%02d", stat,
             (((double)remcap / (double)descap) * 100), hours, minutes, seconds);
-    if(!stat) { free(stat); }
+    SFREE(stat);
     return ret;
 }
 #include <sys/time.h>
 #include <time.h>
 
+#define SFREE(pointer) { if(!pointer) free(pointer); }
+
 static Display *dpy;
 
 /**