Skip to content

Commit 1bf2a98

Browse files
committed
fix memleak
1 parent 997a17f commit 1bf2a98

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

ext/ruby_debug/ruby_debug.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <insns_info.inc>
1010
#include "ruby_debug.h"
1111

12-
#define DEBUG_VERSION "0.11.30.pre5"
12+
#define DEBUG_VERSION "0.11.30.pre6"
1313

1414
#define FRAME_N(n) (&debug_context->frames[debug_context->stack_size-(n)-1])
1515
#define GET_FRAME (FRAME_N(check_frame_number(debug_context, frame)))
@@ -510,18 +510,6 @@ save_call_frame(rb_event_flag_t _event, debug_context_t *debug_context, VALUE se
510510
copy_scalar_args(debug_frame);
511511
}
512512

513-
char*
514-
resolve_symlink(char *file) {
515-
char *result;
516-
#ifdef PATH_MAX
517-
result = (char*)malloc(PATH_MAX);
518-
#else
519-
result = NULL;
520-
#endif
521-
return realpath(file, result);
522-
}
523-
524-
525513
#if defined DOSISH
526514
#define isdirsep(x) ((x) == '/' || (x) == '\\')
527515
#else
@@ -530,9 +518,28 @@ resolve_symlink(char *file) {
530518

531519
int
532520
filename_cmp(VALUE source, char *file) {
533-
char* path;
534-
path = RTEST(resolve_symlinks) ? resolve_symlink(file) : file;
535-
return filename_cmp_impl(source, path);
521+
if (!RTEST(resolve_symlinks)) {
522+
return filename_cmp_impl(source, file);
523+
}
524+
525+
#ifdef PATH_MAX
526+
{
527+
char path[PATH_MAX + 1];
528+
path[PATH_MAX] = 0;
529+
530+
if (realpath(source, path) != NULL)
531+
return filename_cmp_impl(source, path);
532+
else
533+
return filename_cmp_impl(source, file);
534+
}
535+
#else
536+
{
537+
char *path = realpath(file, NULL);
538+
result = filename_cmp_impl(source, path == NULL ? file : path);
539+
free(path);
540+
return result;
541+
}
542+
#endif
536543
}
537544

538545
int

0 commit comments

Comments
 (0)