Skip to content
Browse files

Fixed memory leak in read_port_command

  • Loading branch information...
1 parent ee2adca commit 1d1b9bb5d18eeb6e37445400fa3d536c53465afa @srstrong srstrong committed
Showing with 10 additions and 7 deletions.
  1. +1 −1 c_src/i_port.h
  2. +9 −6 c_src/port.c
View
2 c_src/i_port.h
@@ -66,7 +66,7 @@ void i_decode_list_header(int packet_size, char *port_name, const char *buf, int
void i_decode_tuple_header(int packet_size, char *port_name, const char *buf, int *index, int *arity);
void i_skip_null(int packet_size, char *port_name, const char *buf, int *index);
-long long int read_port_command(int packet_size, char *port_name, unsigned char **buf, char **command, int *index);
+long long int read_port_command(int packet_size, char *port_name, unsigned char **buf, unsigned int *buf_size, char **command, int *index);
long long int read_port(int packet_size, unsigned char **buf, unsigned int *size);
int write_port(int packet_size, ei_x_buff *buff);
int write_buffer_to_port(int packet_size, unsigned char *buffer, int length);
View
15 c_src/port.c
@@ -87,8 +87,8 @@ void file_dump(void *data, int size)
for(n = 1; n <= size; n++) {
if (n % 16 == 1) {
/* store address for this line */
- snprintf(addrstr, sizeof(addrstr), "%.4x",
- ((unsigned int)p-(unsigned int)data) );
+ snprintf(addrstr, sizeof(addrstr), "%.4lx",
+ ((unsigned long)p-(unsigned long)data) );
}
c = *p;
@@ -124,9 +124,9 @@ void file_dump(void *data, int size)
fclose(f);
}
-long long int read_port_command(int packet_size, char *port_name, unsigned char **buf, char **command, int *index)
+long long int read_port_command(int packet_size, char *port_name, unsigned char **buf, unsigned int *buf_size, char **command, int *index)
{
- unsigned int size = BUFF_SIZE;
+ int command_len;
if (*buf == NULL)
{
@@ -135,9 +135,12 @@ long long int read_port_command(int packet_size, char *port_name, unsigned char
FILE_TRACE("BUFFER is null!\n", 0);
return -1;
}
+ *buf_size = BUFF_SIZE;
}
- if (read_port(packet_size, buf, &size) > 0)
+ command_len = read_port(packet_size, buf, buf_size);
+
+ if (command_len > 0)
{
int version, arity;
@@ -158,7 +161,7 @@ long long int read_port_command(int packet_size, char *port_name, unsigned char
i_decode_atom(packet_size, port_name, (char *) *buf, index, command);
FILE_TRACE("Decode ok\n", 0);
- return 1;
+ return command_len;
}
else
{

0 comments on commit 1d1b9bb

Please sign in to comment.
Something went wrong with that request. Please try again.