libzmalloc-0.2/000075500000000000000000000000001201442300500134705ustar00rootroot00000000000000libzmalloc-0.2/Makefile000064400000000000000000000016641201442300500151370ustar00rootroot00000000000000LIBRARY = libzmalloc VERSION=0.1 MAJOR = 0 SHAREDLIB = $(LIBRARY).so SONAME = $(SHAREDLIB).$(MAJOR) INSTALL = install LIBDIR = $(libdir) CC=gcc CFLAGS =$(FLAGS) -I../include $(RPM_OPT_FLAGS) LINK.o = $(CC) $(LDFLAGS) $(FLAGS) $(TARGET_ARCH) LIB_SRC = zmalloc.c LIB_SOBJ = $(LIB_SRC:%.c=%.so) .PHONY: all install clean all: $(SHAREDLIB) install: all $(INSTALL) -pD -m755 $(SHAREDLIB) $(libdir)/$(SHAREDLIB).$(VERSION) @ln -sf $(SHAREDLIB).$(VERSION) $(libdir)/$(SONAME) @ln -sf $(SONAME) $(libdir)/$(SHAREDLIB) $(INSTALL) -pD -m755 zmalloc-ctrl $(bindir)/zmalloc-ctrl $(INSTALL) -pD -m755 zmalloc-enable $(bindir)/zmalloc-enable $(INSTALL) -pD -m755 zmalloc-disable $(bindir)/zmalloc-disable clean: $(RM) $(LIB_SOBJ) $(SHAREDLIB) $(SONAME) core *~ test $(SHAREDLIB): $(LIB_SOBJ) $(LINK.o) -shared -Wl,-soname,$(SONAME) $+ $(OUTPUT_OPTION) ln -sf $(SHAREDLIB) $(SONAME) %.so: %.c $(CC) -c $(CPPFLAGS) -fpic $< $(OUTPUT_OPTION) libzmalloc-0.2/test1.c000064400000000000000000000005731201442300500147010ustar00rootroot00000000000000#include #include #include #define SIZE 100 print_memory(char *c,int size) { int i; for(i=0;i #include #include #define SIZE 100 print_memory(char *c,int size) { int i; for(i=0;i # # The zmalloc utility for the libzmalloc project # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # # Require libshell . shell-error . shell-quote . shell-config . shell-var . shell-args # Backcall for libshell show_help() { cat < Copyright (C) 2012 Andrew V. Stepanov This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. EOF exit } CONFIG="/etc/ld.so.preload" # Test zmalloc is enabled # Return 0 if enabled, otherwise 1 zmalloc_test() { if grep -qs '^/lib/libzmalloc\.so\.0\.1$' "$CONFIG"; then return fi return 1 } # Enable zmalloc zmalloc_enable() { if zmalloc_test; then fatal "libzmalloc is already enabled in system." fi if ! [ -w "$(dirname $CONFIG)" ]; then fatal "Can't write $CONFIG." fi echo '/lib/libzmalloc.so.0.1' >> "$CONFIG" && /sbin/ldconfig test -z "$quiet" && message "libzmalloc now enabled." exit } # Disable zmalloc zmalloc_disable() { if ! zmalloc_test; then fatal "libzmalloc is already disabled in system." fi if ! [ -f "$CONFIG" -a -w "$CONFIG" ]; then fatal "Can't write $CONFIG." fi sed '\,^/lib/libzmalloc.so.0.1$, d' -i "$CONFIG" && /sbin/ldconfig test -z "$quiet" && message "libzmalloc now disabled." exit } # Status zmalloc zmalloc_status() { local ret= if zmalloc_test; then test -z "$quiet" && message "libzmalloc enabled." ret=0 else test -z "$quiet" && message "libzmalloc disabled." ret=1 fi exit $ret } TEMP=`getopt -n $PROG -o e,d,s,$getopt_common_opts -l enable,disable,status,$getopt_common_longopts -- "$@"` || show_usage eval set -- "$TEMP" status= disable= enable= while :; do case "$1" in -s|--status) status="yes" ;; -d|--disable) disable="yes" ;; -e|--enable) enable="yes" ;; --) shift; break ;; *) parse_common_option "$1" ;; esac shift done test -n "$status" && zmalloc_status test -n "$disable" && zmalloc_disable test -n "$enable" && zmalloc_enable show_usage 'Insufficient arguments.' # vim: autoindent tabstop=2 shiftwidth=2 expandtab softtabstop=2 filetype=sh libzmalloc-0.2/zmalloc-disable000075500000000000000000000001271201442300500164600ustar00rootroot00000000000000#!/bin/sh sed '\,^/lib/libzmalloc.so.0.1$, d' -i /etc/ld.so.preload && /sbin/ldconfig libzmalloc-0.2/zmalloc-enable000075500000000000000000000002371201442300500163050ustar00rootroot00000000000000#!/bin/sh if ! grep -qs '^/lib/libzmalloc\.so\.0.1$' /etc/ld.so.preload; then echo '/lib/libzmalloc.so.0.1' >>/etc/ld.so.preload && /sbin/ldconfig fi libzmalloc-0.2/zmalloc.c000064400000000000000000000002631201442300500152760ustar00rootroot00000000000000#define _GNU_SOURCE 1 #include #include #include void *malloc(size_t size){ return calloc(1,size); } void free(void *ptr){ cfree(ptr); }