When allocating the frame table for a NetMon file, use g_try_malloc(),
and fail with ENOMEM if that fails (and the frame table is not empty - g_try_malloc() will return NULL if you ask it to allocate zero bytes). Have an error message for ENOMEM on an open that attempts to tell the user what the problem is without making their head explode. svn path=/trunk/; revision=49673
This commit is contained in:
parent
7658263b0e
commit
6b4c30b69d
@ -1621,6 +1621,49 @@ file_open_error_message(int err, gboolean for_writing)
|
||||
errmsg = "The file \"%s\" could not be created because an invalid filename was specified.";
|
||||
break;
|
||||
|
||||
case ENOMEM:
|
||||
/*
|
||||
* The problem probably has nothing to do with how much RAM the
|
||||
* user has on their machine, so don't confuse them by saying
|
||||
* "memory". The problem is probably either virtual address
|
||||
* space or swap space.
|
||||
*/
|
||||
#if GLIB_SIZEOF_VOID_P == 4
|
||||
/*
|
||||
* ILP32; we probably ran out of virtual address space.
|
||||
*/
|
||||
#define ENOMEM_REASON "it can't be handled by a 32-bit application"
|
||||
#else
|
||||
/*
|
||||
* LP64 or LLP64; we probably ran out of swap space.
|
||||
*/
|
||||
#if defined(_WIN32)
|
||||
/*
|
||||
* You need to make the pagefile bigger.
|
||||
*/
|
||||
#define ENOMEM_REASON "the pagefile is too small"
|
||||
#elif defined(__APPLE__)
|
||||
/*
|
||||
* dynamic_pager couldn't, or wouldn't, create more swap files.
|
||||
*/
|
||||
#define ENOMEM_REASON "your system ran out of swap file space"
|
||||
#else
|
||||
/*
|
||||
* Either you have a fixed swap partition or a fixed swap file,
|
||||
* and it needs to be made bigger.
|
||||
*
|
||||
* This is UN*X, but it's not OS X, so we assume the user is
|
||||
* *somewhat* nerdy.
|
||||
*/
|
||||
#define ENOMEM_REASON "your system is out of swap space"
|
||||
#endif
|
||||
#endif /* GLIB_SIZEOF_VOID_P == 4 */
|
||||
if (for_writing)
|
||||
errmsg = "The file \"%s\" could not be created because" ENOMEM_REASON ".";
|
||||
else
|
||||
errmsg = "The file \"%s\" could not be opened because" ENOMEM_REASON ".";
|
||||
break;
|
||||
|
||||
default:
|
||||
g_snprintf(errmsg_errno, sizeof(errmsg_errno),
|
||||
"The file \"%%s\" could not be %s: %s.",
|
||||
|
@ -359,7 +359,11 @@ int netmon_open(wtap *wth, int *err, gchar **err_info)
|
||||
if (file_seek(wth->fh, frame_table_offset, SEEK_SET, err) == -1) {
|
||||
return -1;
|
||||
}
|
||||
frame_table = (guint32 *)g_malloc(frame_table_length);
|
||||
frame_table = (guint32 *)g_try_malloc(frame_table_length);
|
||||
if (frame_table_length != 0 && frame_table == NULL) {
|
||||
*err = ENOMEM; /* we assume we're out of memory */
|
||||
return -1;
|
||||
}
|
||||
errno = WTAP_ERR_CANT_READ;
|
||||
bytes_read = file_read(frame_table, frame_table_length, wth->fh);
|
||||
if ((guint32)bytes_read != frame_table_length) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user