Re: undelfs warnings fix



> On Thu, 13 Nov 2003, Andrew V. Samoilov wrote:
> 
> > Hello, Pavel!
> >
> > Small fix for last changes.
> 
> The warnings have been fixed already.  I'm not sure about com_err().  See
> "man com_err".  Maybe it's used to override com_err() from the library.

It seems you are right about com_err().  Well, this patch cleans up argument
names for com_err() and also fixes program termination if where is no enough
memory while scanning deleted entries.

As far as I remember there was some problems with g_malloc() & free() mixing,
at least on FreeBSD, so I propose to define free as g_free() for glib2+,
and use free() to release memory, allocated by malloc()/realloc() for 
glib 1.2.x.  I fix this for undelfs, but view->data case in view.c is more
complicated.

-- 
Regards,
Andrew V. Samoilov.
src/ChangeLog:

	* glibcompat.h: Define g_try_realloc as realloc for glib 1.2.x.
	and free as g_free for glib2 and higher.

vfs/ChangeLog:

	* undelfs.c (undelfs_loaddel): Use g_try_malloc()/g_try_relloc()
	since we want to recover and not abort the program if we don't 
	have enough memory.
	(com_err): Clean up argument names.

--- ChangeLog~	Tue Nov 11 14:20:01 2003
+++ ChangeLog	Fri Nov 14 12:26:50 2003
@@ -257,7 +257,7 @@
 	* glibcompat.h: Define g_try_malloc as malloc for glib 1.2.x.
 
 	* view.c (load_view_file): Use g_try_malloc() because the
-	failure to allcate memory is acceptable here.
+	failure to allocate memory is acceptable here.
 	Reported by Pavel S. Shirshov <pavelsh mail ru>
 
 2003-10-14  Pavel Roskin  <proski gnu org>
--- src/glibcompat.h~	Wed Oct 22 13:53:32 2003
+++ src/glibcompat.h	Fri Nov 14 12:29:09 2003
@@ -21,6 +21,9 @@
 #if GLIB_MAJOR_VERSION < 2
 gsize g_strlcpy (gchar *dest, const gchar *src, gsize dest_size);
 #define g_try_malloc(x) malloc(x)
+#define g_try_realloc(x) realloc(x)
+#else
+#define free(x) g_free(x)
 #endif				/* GLIB_MAJOR_VERSION < 2 */
 
 #endif				/* !__MC_GLIBCOMPAT_H */
--- vfs/undelfs.c~	Thu Nov 13 20:01:26 2003
+++ vfs/undelfs.c	Fri Nov 14 12:14:04 2003
@@ -177,12 +177,12 @@ undelfs_loaddel (void)
 
     max_delarray = 100;
     num_delarray = 0;
-    delarray = g_new (struct deleted_info, max_delarray);
+    delarray = g_try_malloc (sizeof (struct deleted_info) * max_delarray);
     if (!delarray) {
 	message (1, undelfserr, _(" not enough memory "));
 	return 0;
     }
-    block_buf = g_malloc (fs->blocksize * 3);
+    block_buf = g_try_malloc (fs->blocksize * 3);
     if (!block_buf) {
 	message (1, undelfserr, _(" while allocating block buffer "));
 	goto free_delarray;
@@ -224,15 +224,18 @@ undelfs_loaddel (void)
 	}
 	if (lsd.free_blocks && !lsd.bad_blocks) {
 	    if (num_delarray >= max_delarray) {
-		max_delarray += 50;
-		delarray =
-		    g_renew (struct deleted_info, delarray, max_delarray);
-		if (!delarray) {
+		struct deleted_info *delarray_new =
+		    g_try_realloc (delarray,
+				   sizeof (struct deleted_info) *
+				   (max_delarray + 50));
+		if (!delarray_new) {
 		    message (1, undelfserr,
 			     _
 			     (" no more memory while reallocating array "));
 		    goto error_out;
 		}
+		delarray = delarray_new;
+		max_delarray += 50;
 	    }
 
 	    delarray[num_delarray].ino = ino;
@@ -264,19 +261,19 @@
   error_out:
     ext2fs_close_inode_scan (scan);
   free_block_buf:
+    free (block_buf);
-    g_free (block_buf);
     block_buf = NULL;
   free_delarray:
-    g_free (delarray);
+    free (delarray);
     delarray = NULL;
     return 0;
 }
 
-void com_err (const char *str, long err_code, const char *s2, ...)
+void com_err (const char *whoami, long err_code, const char *format, ...)
 {
     char *cptr;
 
-    cptr = g_strdup_printf (" %s (%s: %ld) ", s2, str, err_code);
+    cptr = g_strdup_printf (" %s (%s: %ld) ", format, whoami, err_code);
     message (1, _(" Ext2lib error "), cptr);
     g_free (cptr);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]