Few patches ( realloc and const )
andreas moroder
claudiamoroder at st-ulrich.suedtirol.net
Sun Nov 25 08:31:06 GMT 2001
Hello,
I made a few patches regarding:
1. User of realloc
days ago I posted a list of realloc usages and possible memory leaks. Here
are my patches.
2. const
If you run objdump -x smbd | grep -F .data | sort +4 | more over smbd
You get the list of .data segments. Many of the contain constant data arrays.
I made a few patches using const. There are many of them to do, but with this
patch the usage of .data is 5K lower
If this patches are welcome, I will continue.
The patches are against 2.2.2 cvs from saturday
Bye
Andreas
Only in source: .indent.pro
diff -r -u --exclude-from=exclude source/include/kanji.h
andreas/include/kanji.h
--- source/include/kanji.h Tue Mar 27 01:12:32 2001
+++ andreas/include/kanji.h Sun Nov 25 17:02:23 2001
@@ -265,7 +265,7 @@
int euc;
} sjis_euc_map_t;
-static sjis_euc_map_t euc3conv2[] = {
+static const sjis_euc_map_t euc3conv2[] = {
{0x8754 , 0xf3fd},
{0x8755 , 0xf3fe},
{0x8756 , 0xf4a1},
@@ -284,7 +284,7 @@
/* IBM Kanji to EUC 3byte */
-static int euc3conv[] = {
+static const int euc3conv[] = {
/* 0xfa40 */
0xf3f3, 0xf3f4, 0xf3f5, 0xf3f6, 0xf3f7, 0xf3f8, 0xf3f9, 0xf3fa, 0xf3fb,
0xf3fc, 0xf3fd, 0xf3fe, 0xf4a1, 0xf4a2, 0xf4a3, 0xf4a4,
/* 0xfa50 */
diff -r -u --exclude-from=exclude source/lib/util.c andreas/lib/util.c
--- source/lib/util.c Fri Nov 23 16:59:14 2001
+++ andreas/lib/util.c Sun Nov 25 17:19:07 2001
@@ -63,7 +63,7 @@
int Protocol = PROTOCOL_COREPLUS;
/* a default finfo structure to ensure all fields are sensible */
-file_info def_finfo = {-1,0,0,0,0,0,0,"",""};
+const file_info def_finfo = {-1,0,0,0,0,0,0,"",""};
/* this is used by the chaining code */
int chain_size = 0;
diff -r -u --exclude-from=exclude source/lib/util_unistr.c
andreas/lib/util_unistr.c
--- source/lib/util_unistr.c Fri Nov 23 16:59:14 2001
+++ andreas/lib/util_unistr.c Sun Nov 25 16:55:19 2001
@@ -1060,19 +1060,19 @@
********************************************************************/
typedef struct {
- smb_ucs2_t lower;
- smb_ucs2_t upper;
- unsigned char flags;
+ const smb_ucs2_t lower;
+ const smb_ucs2_t upper;
+ const unsigned char flags;
} smb_unicode_table_t;
#define TABLE1_BOUNDARY 9450
#define TABLE2_BOUNDARY 64256
-static smb_unicode_table_t map_table1[] = {
+static const smb_unicode_table_t map_table1[] = {
#include "unicode_map_table1.h"
};
-static smb_unicode_table_t map_table2[] = {
+static const smb_unicode_table_t map_table2[] = {
#include "unicode_map_table2.h"
};
diff -r -u --exclude-from=exclude source/libsmb/errormap.c
andreas/libsmb/errormap.c
--- source/libsmb/errormap.c Fri Nov 23 16:59:15 2001
+++ andreas/libsmb/errormap.c Sun Nov 25 17:00:25 2001
@@ -22,7 +22,7 @@
#include "includes.h"
/* NT status -> dos error map */
-static struct {
+static const struct {
uint8 dos_class;
uint32 dos_code;
NTSTATUS ntstatus;
@@ -819,7 +819,7 @@
};
/* errmap NTSTATUS->Win32 */
-static struct {
+static const struct {
NTSTATUS ntstatus;
WERROR werror;
} ntstatus_to_werror_map[] = {
diff -r -u --exclude-from=exclude source/nsswitch/winbind_nss.c
andreas/nsswitch/winbind_nss.c
--- source/nsswitch/winbind_nss.c Tue Jul 24 09:26:49 2001
+++ andreas/nsswitch/winbind_nss.c Sat Nov 24 15:17:21 2001
@@ -822,7 +822,7 @@
/* Add to buffer */
if (*start == *size && limit <= 0) {
- groups = realloc(
+ groups = Realloc(
groups, 2 * (*size) * sizeof(*groups));
if (!groups) goto done;
*size *= 2;
diff -r -u --exclude-from=exclude source/param/params.c andreas/param/params.c
--- source/param/params.c Sat Oct 20 23:23:37 2001
+++ andreas/param/params.c Sat Nov 24 15:30:47 2001
@@ -415,13 +415,15 @@
if( i > (bSize - 2) ) /* Make sure there's enough room. */
{
- bSize += BUFR_INC;
- bufr = Realloc( bufr, bSize );
- if( NULL == bufr )
+ char *tb;
+ tb = Realloc( bufr, bSize + BUFR_INC);
+ if( NULL == tb )
{
- DEBUG(0, ("%s Memory re-allocation failure.", func) );
- return( False );
+ DEBUG(0, ("%s Memory re-allocation failure.", func) );
+ return( False );
}
+ bufr=tb;
+ bSize += BUFR_INC;
}
switch( c )
diff -r -u --exclude-from=exclude source/passdb/pdb_ldap.c
andreas/passdb/pdb_ldap.c
--- source/passdb/pdb_ldap.c Fri Nov 9 23:13:32 2001
+++ andreas/passdb/pdb_ldap.c Sat Nov 24 15:39:59 2001
@@ -296,7 +296,7 @@
if (mods[i] == NULL)
{
- mods = (LDAPMod **) realloc (mods, (i + 2) * sizeof (LDAPMod *));
+ mods = (LDAPMod **) Realloc (mods, (i + 2) * sizeof (LDAPMod *));
if (mods == NULL)
{
DEBUG(0, ("make_a_mod: out of memory!\n"));
@@ -320,7 +320,7 @@
if (mods[i]->mod_values != NULL) {
for (; mods[i]->mod_values[j] != NULL; j++);
}
- mods[i]->mod_values = (char **)realloc(mods[i]->mod_values,
+ mods[i]->mod_values = (char **)Realloc(mods[i]->mod_values,
(j + 2) * sizeof (char *));
if (mods[i]->mod_values == NULL) {
diff -r -u --exclude-from=exclude source/printing/nt_printing.c
andreas/printing/nt_printing.c
--- source/printing/nt_printing.c Fri Nov 23 16:59:30 2001
+++ andreas/printing/nt_printing.c Sun Nov 25 16:57:52 2001
@@ -53,7 +53,7 @@
forms it wants and in the ORDER it wants them (note: DEVMODE papersize is an
array index). Letter is always first, so (for the current code) additions
always put things in the correct order. */
-static nt_forms_struct default_forms[] = {
+static const nt_forms_struct default_forms[] = {
{"Letter",0x1,0x34b5c,0x44368,0x0,0x0,0x34b5c,0x44368},
{"Letter Small",0x1,0x34b5c,0x44368,0x0,0x0,0x34b5c,0x44368},
{"Tabloid",0x1,0x44368,0x696b8,0x0,0x0,0x44368,0x696b8},
diff -r -u --exclude-from=exclude source/tdb/tdb.c andreas/tdb/tdb.c
--- source/tdb/tdb.c Wed Oct 17 00:11:21 2001
+++ andreas/tdb/tdb.c Sat Nov 24 15:22:10 2001
@@ -659,6 +659,7 @@
{
struct list_struct rec;
tdb_off offset;
+ void *tmap;
if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
TDB_LOG((tdb, 0, "lock failed in tdb_expand\n"));
@@ -689,9 +690,19 @@
tdb->map_size += size;
- if (tdb->flags & TDB_INTERNAL)
- tdb->map_ptr = realloc(tdb->map_ptr, tdb->map_size);
- else {
+ if (tdb->flags & TDB_INTERNAL) {
+ tmap = Realloc(tdb->map_ptr, tdb->map_size);
+ if (tmap==NULL) {
+ /* Should memory really be freed ? */
+ /* must map_size be set to 0 ? */
+ SAFE_FREE(tdb->map_ptr);
+ tdb->map_ptr=NULL;
+ /* Can i use DEBUG here ? */
+ goto fail;
+ } else {
+ tdb->map_ptr = tmap;
+ }
+ } else {
/*
* We must ensure the file is remapped before adding the space
* to ensure consistency with systems like OpenBSD where
More information about the samba-technical
mailing list